Error when load data from csv with liquibase into enum column

Viewed 338

I came across an error and can't find a way to solve it. Error occurs when I'm trying to load data from csv into the table with enum column using Liquibase.

In first, I create the enum type and table like this:

<changeSet author="enbirr" id="create-table">
<sql>CREATE TYPE product_type AS ENUM (
        'deposits',
        'credits'
    );
</sql>

<createTable tableName="test_table">
    <column name="guid" type="uuid">
        <constraints primaryKey="true" primaryKeyName="test_table_pk"/>
    </column>
    <column name="product" type="product_type">
        <constraints nullable="false"/>
    </column>
</createTable> 
</changeSet>

Then, I insert data from data.csv:

 "guid"|"product"
 "5672b9c1-8fd3-4dc8-a67f-4498d9747c66"|"deposits"
 "3458f613-ab6b-462b-8983-52dfac238f56"|"credits"

using next changeset:

<changeSet author="enbirr" id="fill-data">
        <loadData
                file="csv/data.csv"
                relativeToChangelogFile="true"
                separator="|"
                tableName="test_table"/>
</changeSet>

And when I start my Java app that runs these Liquibase changesets, I receive the next error:

Caused by: org.postgresql.util.PSQLException: ERROR: column "product" is of type product_type but expression is of type character varying
  Hint: You will need to rewrite or cast the expression.
  Position: 123

Anybody knows how to teach Liquibase to cast string to custom enum type?

PS version of liquibase-core - 4.5.0

1 Answers

I am using type other and then solved

Related