To leverage Liquibase createIndex
and support different RDBMSes, you will need to use modifySql
(until https://liquibase.jira.com/browse/CORE-419 is fixed, as pointed out by @Vadzim.
For Oracle and PostgreSQL the syntax will be simple (unless PostgreSQL is used in "always quote column names" mode):
<modifySql>
<replace replace="COL1NAME" with="COL1NAME ASC"/>
<replace replace="COL2NAME" with="COL2NAME DESC"/>
</modifySql>
Howver, this won't work on SQL Server. Liquibase wraps column names in [...]
on SQL Server, so you would need something like
<modifySql>
<regExpReplace replace="\bCOL1NAME\b[^,) ]*" with="$0 ASC" />
<regExpReplace replace="\bCOL2NAME\b[^,) ]*" with="$0 DESC" />
</modifySql>
(tested on oracle, postgresql, sql server and h2)
However, the above is as ugly as it looks. I suppose using simple <sql>
yields more readable results and, honestly, it does not seem less portable.
<column name="a_column_name DESC"/>
? This might cause portability issues, of course. – MoralizeCREATE INDEX idx_name ON my_table (**"m_column DESC"**)
– Stringed