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.
For more information, see Working with Command Parameters. You can set this parameter in the following ways:
|Liquibase properties file||
|Global CLI parameter||
JVM system property
|Liquibase Environment Variables||macOS/Linux:
Note: These commands only apply to the current shell. To set permanent environment variables, see Liquibase Environment Variables.
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'