Change: ‘mergeColumns’

Concatenates the values in two columns, joins them by with string, and stores the resulting value in a new column.

Available Attributes

NameDescriptionRequired ForSupportsSince
catalogNameName of the catalogall
column1NameName of the column containing the first half of the dataallall
column2NameName of the column containing the second half of the dataallall
finalColumnNameName of the column to createallall
finalColumnTypeData type of the column to createallall
joinStringString to place include between the values from column1 and column2 (may be empty)all
schemaNameName of the schemaall
tableNameName of the table containing the columns to joinallall
<changeSet author="liquibase-docs" id="mergeColumns-example">
    <mergeColumns catalogName="cat"
            column1Name="first_name"
            column2Name="last_name"
            finalColumnName="full_name"
            finalColumnType="varchar(255)"
            joinString="A String"
            schemaName="public"
            tableName="person"/>
</changeSet>
changeSet:
  id: mergeColumns-example
  author: liquibase-docs
  changes:
  - mergeColumns:
      catalogName: cat
      column1Name: first_name
      column2Name: last_name
      finalColumnName: full_name
      finalColumnType: varchar(255)
      joinString: A String
      schemaName: public
      tableName: person
{
  "changeSet": {
    "id": "mergeColumns-example",
    "author": "liquibase-docs",
    "changes": [
      {
        "mergeColumns": {
          "catalogName": "cat",
          "column1Name": "first_name",
          "column2Name": "last_name",
          "finalColumnName": "full_name",
          "finalColumnType": "varchar(255)",
          "joinString": "A String",
          "schemaName": "public",
          "tableName": "person"
        }
      }]
    
  }
}

SQL Generated From Above Sample (MySQL)

ALTER TABLE public.person ADD full_name VARCHAR(255) NULL;

UPDATE cat.person SET full_name = CONCAT_WS(first_name,
 'A String',
 last_name);

ALTER TABLE public.person DROP COLUMN first_name;

ALTER TABLE public.person DROP COLUMN last_name;

Database Support

DatabaseNotesAuto Rollback
DB2SupportedNo
DerbyNot SupportedNo
FirebirdSupportedNo
H2SupportedNo
HyperSQLSupportedNo
InformixSupportedNo
MySQLSupportedNo
OracleSupportedNo
PostgreSQLSupportedNo
SQL ServerSupportedNo
SQLiteSupportedNo
SybaseSupportedNo
Sybase AnywhereSupportedNo

Missing, incomplete or wrong information? Please send a pull request