mergeColumns

The mergeColumns Change Type concatenates the values in two columns and joins them with a string. The Change Type stores the resulting value in a new column.

Uses

You can typically use the mergeColumns Change Type when you want to combine the values from two columns into one.

Running the mergeColumns Change Type

To run this Change Type, follow these steps:

  1. Add the Change Type to your changeset, as shown in the examples on this page.
  2. Specify any required attributes. Use the table on this page to see which ones your database requires.
  3. Deploy your changeset by running the update command:
  4. liquibase update

Now, you should see a new merged column.

Available attributes

Name Description Required for Supports
catalogName

Name of the catalog

all
column1Name Name of the column containing the first half of the data all all
column2Name Name of the column containing the second half of the data all all
finalColumnName Name of the column to create all all
finalColumnType

Data type of the column.

To help make scripts database-independent, Liquibase automatically converts the following generic data types to the correct database implementation: BIGINT, BLOB, BOOLEAN, CHAR, CLOB, CURRENCY, DATE, DATETIME, DECIMAL, DOUBLE, FLOAT, INT, MEDIUMINT, NCHAR, NUMBER, NVARCHAR, SMALLINT, TIME, TIMESTAMP, TINYINT, UUID, VARCHAR, XML.

Also, specifying a java.sql.Types.* type is converted to the correct type as well. For example:

  • java.sql.Types.TIMESTAMP
  • java.sql.Types.VARCHAR(255)
all all
joinString

The string to place between the values from column1 and column2 (may be empty)

all
schemaName

Name of the schema

all
tableName Name of the table containing the columns to join all all

Examples

--liquibase formatted sql

--changeset liquibase-docs:mergeColumns-example
ALTER  TABLE  public.person  ADD  full_name  VARCHAR(255)  NULL;
UPDATE  cat.person  SET  full_name  =  CONCAT_WS('A String', 
first_name,last_name);
ALTER  TABLE  public.person  DROP  COLUMN  first_name;
ALTER  TABLE  public.person  DROP  COLUMN  last_name;
databaseChangeLog:
-  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
{
    "databaseChangeLog": [
        {
            "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"
                        }
                    }
                ]
            }
        }
    ]
}
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:pro="http://www.liquibase.org/xml/ns/pro"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
        http://www.liquibase.org/xml/ns/pro
        http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd">

    <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>

</databaseChangeLog>

Database support

Database Notes Auto Rollback
DB2/LUW Supported No
DB2/z Not Supported No
Derby Not Supported No
Firebird Supported No
Google BigQuery 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
Snowflake Supported No
SQL Server Supported No
SQLite Supported No
Sybase Supported No
Sybase Anywhere Supported No