Using Sequence value in loadData ChangeSet

Hi,

 

I started using liquibase recently for maintaining the DB scripts in our project. I need to use the sequence generated primary key value as input to csv file to insert the data.

 

Following is my change set xml:

 


                    <loadData tableName=“EMPLOYEE” file=“UpdateEmpData.csv”   >
                   
                   
                   
             
   

In csv, I have the following:

 

EMPLOYEE_ID,NAME
employee_seq.nextval,JIM
employee_seq.nextval,TOM

 

When I execute I get the following error:

 

liquibase.exception.MigrationFailedException: Migration failed for change set C:/sample/Liquibase/ChangeLog/db.changelog_sequence.xml::7::sequser:
     Reason: liquibase.exception.DatabaseException: Error executing SQL INSERT INTO EMPLOYEE (EMPLOYEE_ID, NAME) VALUES (‘employee_seq.nextval’, ‘MEERA’): ORA-01722: invalid number
:
          Caused By: Error executing SQL INSERT INTO EMPLOYEE (EMPLOYEE_ID, NAME) VALUES (‘employee_seq.nextval’, ‘MEERA’): ORA-01722: invalid number
:
          Caused By: ORA-01722: invalid number

        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:347)
        at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:27)
        at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:58)
        at liquibase.Liquibase.update(Liquibase.java:113)
        at liquibase.integration.commandline.Main.doMigration(Main.java:779)
        at liquibase.integration.commandline.Main.main(Main.java:133)
Caused by: liquibase.exception.DatabaseException: Error executing SQL INSERT INTO EMPLOYEE (EMPLOYEE_ID, NAME) VALUES (‘employee_seq.nextval’, ‘JIM’): ORA-01722: invalid number

        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:62)
        at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:104)
        at liquibase.database.AbstractDatabase.execute(AbstractDatabase.java:1075)
        at liquibase.database.AbstractDatabase.executeStatements(AbstractDatabase.java:1059)
        at liquibase.changelog.ChangeSet.execute(ChangeSet.java:317)
        … 5 more
Caused by: java.sql.SQLException: ORA-01722: invalid number

 

 

When I searched the forum, I got to know that we need to use ‘valueComputed’ for and type=“COMPUTED” for loadData. But still I am getting this issue.

 

Could anyone please provide any inputs?

 

When I looked into the Liquibase code, I see this code in LoadDataChange.generateStatements(…)

 

else if (columnConfig.getType().equalsIgnoreCase(“COMPUTED”))
                valueConfig.setValue(value.toString());

 

Should it be  valueConfig.setValue(value.toString()); -> valueConfig.setValueComputed()?

Please let me know what needs to be done.

Try following

Worked for me