I'm trying to check if a table exists, then execute a changeset. But it seems the precondition is not executed properly. Any suggestions on how to check if table exists and execute a statement?
Liquibase Script:
databaseChangeLog:
- preConditions:
- onFail: MARK_RAN
- sqlCheck:
expectedResult: 1
sql: SELECT count(*) FROM information_schema.TABLES WHERE TABLE_NAME = TABLE_MAY_NOT_EXIST
- changeSet:
id: 1001001
author: upgrade_author
changes:
- sql:
sql: UPDATE MY_TABLE SET COL_A = (SELECT TOP 1 COL_A FROM TABLE_MAY_NOT_EXIST ORDER BY COL_A DESC)
stripComments: true
Error Log:
Caused by: liquibase.exception.DatabaseException: Table "TABLE_MAY_NOT_EXIST" not found; SQL statement:
UPDATE MY_TABLE SET COL_A = (SELECT TOP 1 COL_A FROM TABLE_MAY_NOT_EXIST ORDER BY COL_A DESC) [42102-197] [Failed SQL: UPDATE MY_TABLE SET COL_A = (SELECT TOP 1 COL_A FROM TABLE_MAY_NOT_EXIST ORDER BY COL_A DESC)]
at liquibase.executor.jvm.JdbcExecutor$ExecuteStatementCallback.doInStatement(JdbcExecutor.java:356) ~[liquibase-core-3.6.3.jar:na]
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:57) ~[liquibase-core-3.6.3.jar:na]
at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:125) ~[liquibase-core-3.6.3.jar:na]
at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1229) ~[liquibase-core-3.6.3.jar:na]
at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1211) ~[liquibase-core-3.6.3.jar:na]
at liquibase.changelog.ChangeSet.execute(ChangeSet.java:600) ~[liquibase-core-3.6.3.jar:na]