首页 > 解决方案 > How to update the records using liquibase loadUpdateData and csv file

问题描述

I added new column to table and update the data for existing records if the name exists using liquibase loadUpdateData. Below is the snippet i tried to update but seems to be not working. Can some one help me what i am doing wrong.

<changeSet author="user_name" id="1" objectQuotingStrategy="QUOTE_ALL_OBJECTS">
        <addColumn tableName="table_name">
            <column name="last_name" type="VARCHAR2(20 CHAR)"/>
        </addColumn>
    </changeSet>
    <changeSet author="user_name" id="2" objectQuotingStrategy="QUOTE_ALL_OBJECTS">
        <loadUpdateData  encoding="UTF-8"
                  tableName="table_name"
                         primaryKey="ID"
                         onlyUpdate="true"
                  file="../data/update_user.csv"
                  relativeToChangelogFile="true"
                  quotchar='"'
                  separator=','>
            <column name="ID" type="NUMERIC"/>
            <column name="NAME" type="STRING"/>
            <column name="LAST_NAME" type="STRING"/>
        </loadUpdateData >
    </changeSet>

Before adding column:

ID NAME
1  aaa
2  bbb
3  ccc
4  ddd

After adding new column and adding data to csv file: expected output

ID NAME LAST_NAME
1  aaa  zzz
2  bbb  yyy
3  ccc  qqq
4  ddd  www

But it is not updating i am getting

ID NAME LAST_NAME
1  aaa  null
2  bbb  null
3  ccc  null
4  ddd  null

update_user.csv file

ID,NAME,LAST_NAME
1,aaa,zzz
2,bbb,yyy
3,ccc,qqq
4,ddd,www

Did i do any thing wrong? I want only update and ignore insert if record not found. If id or name exists it should update that row with the last_name value given in csv file. I am using liquibase 3.6.1 version

标签: liquibase

解决方案


推荐阅读