diff-column-order

The diff-column-order global parameter is a Boolean that determines whether the diff command and diff-changelog command compare the column order of a table between two databases. The default value is false.

Relational databases

Relational databases organize data as relations (tables) that contain rows and columns. This data is ordered in the computer’s physical memory, but you’re meant to access it by name (column name, column id…), not ordinal position (column 1, column 2…).

It’s possible to add or select columns by ordinal position if you use the statement SELECT * FROM my_table and run getValue(1) on the result set rather than getValue(name). However, this is generally considered bad practice.

This means the diff-column-order parameter usually isn’t relevant when you compare two databases.

Uses

The diff command compares two databases and reports any differences to STDOUT. The diff-changelog command compares two databases and generates a changelog containing changesets that you can deploy to resolve any differences.

If you’re comparing two databases with diff or diff-changelog, it’s best practice to leave diff-column-order at the default value of false. If you set it to true and run diff-changelog, Liquibase cannot create changesets to resolve differences in column order.

However, if you use external comparison or reporting tools which cannot easily handle differences in column order data, you can set diff-column-order to true. This way, Liquibase handles order differences before passing any data to these external tools.

Syntax

You can set this parameter in the following ways:

Option Syntax
Liquibase properties file
liquibase.diffColumnOrder: <true|false>
Global flow file argument (example)
stages:
  Default:
    actions:
      - type: liquibase
        command: diff
        globalArgs: { diff-column-order: "<true|false>" }
Global CLI parameter
liquibase
 --diff-column-order=<true|false> diff
 --changelog-file=example-changelog.xml

JVM system property (JAVA_OPTS Environment Variable)

JAVA_OPTS=-Dliquibase.diffColumnOrder=<true|false>
Liquibase Environment Variables
LIQUIBASE_DIFF_COLUMN_ORDER=<true|false>

For more information, see Working with Command Parameters.

Output

If you set diff-column-order to true and run the diff command on two databases containing tables with opposite column orders, the output includes:

Changed Column(s):
     PUBLIC.TEST_TABLE.TEST_NAME
          order changed from '2' to '1'
     PUBLIC.TEST_TABLE.TEST_ID
          order changed from '1' to '2'

Related links