SQL Preconditions Help

Hello,

I am new to Liquibase and working my way through its functionalies.
Please help me with the following issue:

Regarding the SQL preconditions, is there a way to add complex SQL\PLSQL queries to the preconditions line, like:
–precondition-sql-check expectedResult:100 CREATE OR REPLACE FUNCTION totalRecords () RETURNS integer AS total declare total integer; BEGIN SELECT count(*) into total FROM schemaname.persons; RETURN total; END; total LANGUAGE plpgsql; select totalRecords();

The above query is just an example, as I will probably have to add complex functions or PLSQL code blocks in the prereconditions.
Is this possible?

Thank you,
CosminH

Hi @CosminH !

Welcome to the Liquibase community. Sorry for the late reply.

Liquibase preconditions that would come close to a complex sql logic based check would be the sqlcheck.

From the documentation:

Executes an SQL string and checks the returned value. The SQL must return a single row with a single value. To check numbers of rows, use the “count” SQL function. To check for ranges of values, perform the check in the SQL and return a value that can be easily compared against.

You can have any SQL you want, as long as it returns:

  • A single row
  • A single value

I hope that helps.

Ronak