Additional "GO" after liquibase update

Viewed 902

After update to liquibase 3.6.1 our old <sql> changeSets broke if they used DECLARE variables.

Apparently additional GO statements are now added where there are empty rows, this is not how it used to work and it now makes our old files throw liquibase.exception.DatabaseException: Must declare the scalar variable "@foo".

How would we either get around this or fix our older files to work on old database copies without being run again on up to date ones?

1 Answers

The scope of T-SQL Variables is at the T-SQL batch. Batch is completed with the "GO" command. Therefore, after GO, @foo would have to be re-declared.

For example:

DECLARE @foo int = 0;

GO

SELECT @foo; -- This line will give an error.

If the GO is moved to the end, then it will work, and return the value of @foo.

DECLARE @foo int = 1;

SELECT @foo; -- This line will return 1.

GO

Batch Scope is not a new behavior of SQL Server, it's been the behavior since version 1.

Try looking at LiquidBase's 'sqlFile' tag, and see if the endDelimiter attribute or splitStatements attribute have been set incorrectly.

Related