loadUpdateData

Loads or updates data from a CSV file into an existing table. Differs from loadData by issuing a SQL batch that checks for the existence of a record. If found, the record is UPDATEd, else the record is INSERTed. Also, generates DELETE statements for a rollback.

A value of NULL in a cell will be converted to a database NULL rather than the string ‘NULL’

Available attributes

Name Description Required for Supports Since
catalogName Name of the catalog all 3.0
commentLineStartsWith Lines starting with this are treated as comment and ignored. all
encoding Encoding of the CSV file (defaults to UTF-8) all
file CSV file to load all all
onlyUpdate If true, records with no matching database record should be ignored all 3.3
primaryKey Comma delimited list of the columns for the primary key all all
quotchar The quote character for string fields containing the separator character. all
relativeToChangelogFile Whether the file path relative to the root changelog file rather than to the classpath. all
schemaName Name of the schema all
separator Character separating the fields. all
tableName Name of the table to insert or update data in all all
usePreparedStatements Use prepared statements instead of insert statement strings if the DB supports it all

Nested properties

Name Description Required for Supports Multiple allowed
columns? / column Column mapping and defaults can be defined. The 'header' or 'index' attributes needs to be defined if the header name in the CSV is different than the column name needs to be inserted If no `column` defined at all, the type it is taken from the DB. Otherwise for non-string columns the type definition might be required all yes

Nested property attributes

Name Name of the column (Required)
type Data type of the column. Its value has to be one of the LOAD_DATA_TYPE
header Name of the column in the CSV file from which the value for the column shall be taken if its different from the column name. Ignored if index is also defined.
index Index of the column in the CSV file from which the value for the column shall be taken

XML example

<changeSet  author="liquibase-docs"  id="loadUpdateData-example">  
    <loadUpdateData  catalogName="cat"  
            commentLineStartsWith="//"  
            encoding="UTF-8"  
            file="example/users.csv"  
            onlyUpdate="true"  
            primaryKey="pk_id"  
            quotchar="'"  
            relativeToChangelogFile="true"  
            schemaName="public"  
            separator=";"  
            tableName="person"  
            usePreparedStatements="true">  
        <column  header="header1"  
                name="id"  
                type="NUMERIC"/>  
        <column  index="3"  
                name="name"  
                type="BOOLEAN"/>  
    </loadUpdateData>  
</changeSet>

YAML example

changeSet:  
  id:  loadUpdateData-example  
  author:  liquibase-docs  
  changes:  
  -  loadUpdateData:  
      catalogName:  cat  
      columns:  
      -  column:  
          header:  header1  
          name:  id  
          type:  NUMERIC  
      -  column:  
          index:  3  
          name:  name  
          type:  BOOLEAN  
      commentLineStartsWith:  //  
      encoding:  UTF-8  
      file:  example/users.csv  
      onlyUpdate:  true  
      primaryKey:  pk_id  
      quotchar:  ''''  
      relativeToChangelogFile:  true  
      schemaName:  public  
      separator:  ;  
      tableName:  person  
      usePreparedStatements:  true

JSON example

{  "changeSet":  {  "id":  "loadUpdateData-example",  "author":  "liquibase-docs",  "changes":  [  {  "loadUpdateData":  {  "catalogName":  "cat",  "columns":  [  {  "column":  {  "header":  "header1",  "name":  "id",  "type":  "NUMERIC"  }  },  {  "column":  {  "index":  3,  "name":  "name",  "type":  "BOOLEAN"  }  }]  ,  "commentLineStartsWith":  "//",  "encoding":  "UTF-8",  "file":  "example/users.csv",  "onlyUpdate":  true,  "primaryKey":  "pk_id",  "quotchar":  "'",  "relativeToChangelogFile":  true,  "schemaName":  "public",  "separator":  ";",  "tableName":  "person",  "usePreparedStatements":  true  }  }]  }  }

Database support

Database Notes Auto rollback
DB2/LUW Supported No
DB2/z Supported No
Derby Supported No
Firebird Supported No
H2 Supported No
HyperSQL Supported No
INGRES Supported No
Informix Supported No
MariaDB Supported No
MySQL Supported No
Oracle Supported No
PostgreSQL Supported No
SQL Server Supported No
SQLite Supported No
Sybase Supported No
Sybase Anywhere Supported No