Sql for column exist

Just want to verify if this is the right precondition for SQL --precondition-column-exist tableName:tbl_name columnName:fld_id

Still new to liquibase. Thanks.

In SQL format, the only precondition that exists is “sql-check”, where you write you own check query.

This example is how you would check for a column in Oracle:

–precondition-sql-check expectedResult:0 SELECT COUNT(*) FROM dba_tab_columns where owner =
‘SCOTT’ and table_name = ‘TIGER’ and column_name = ‘NAME’

You will need to provide the query appropriate for your DBMS platform.

Make sure to set the appropriate “expectedResult” value (1=“column exists”, 0=“column doesn’t exist”), which will determine if your changeset will execute or not.

Oh sorry for the confusion. Its how to check if a field exist on the table on sql syntax all examples i’ve seen are all on xml syntax. I just want to verify. Thank you

What I provided also works for SQL-Server, you just replace the “column check” query.

1 Like