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
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
id…), not ordinal position (column
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.
diff command compares two databases and reports any differences to
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-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
true. This way, Liquibase handles order differences before passing any data to these external tools.
You can set
diff-column-order in four ways:
- In the Liquibase properties file
- As a global parameter in the CLI
- As a JVM system property
- As an environment variable (Liquibase Pro)
Liquibase properties file parameter
In Liquibase 4.1+, add the following to Liquibase properties file:
CLI global parameter
In your command line, use a global parameter with a single Liquibase command:
Java system property
In your command line, use the JAVA_OPTS Environment Variable to set a JVM system property:
Note: To use a Liquibase command alongside
&& liquibase <command> to the end of your input.
Environment variable (Liquibase Pro)
In Liquibase Pro, set an environment variable:
Note: These environment variable commands only apply to the current shell. If you need to pass an environment variable to a child process without affecting the parent process, you can use the
export command on Mac/Linux or the
setx command on Windows.
If you set
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'