mergeColumns

The mergeColumns Change Type concentrates the values in two columns and joins them with a string. This 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: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)

For Snowflake, Liquibase also implements BINARY, TIME, and TIMESTAMP_NTZ.

For Databricks, Liquibase also implements ARRAY<INT> and ARRAY<STRING>, MAP, and STRUCT variable types.

Note: To specify a complex Databricks type like ARRAY<STRING> in an XML changelog, you must specify the escape sequences &lt; and &gt; rather than < and >. See createTable.

For more information, see Liquibase Data Type Handling.

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

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

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

mergeColumns - Liquibase