The ‘sql’ tag allows you to specify whatever sql you want. It is useful for complex changes that aren’t supported through Liquibase’s automated refactoring tags and to work around bugs and limitations of Liquibase. The SQL contained in the sql tag can be multi-line.
The createProcedure refactoring is the best way to create stored procedures.
The ‘sql’ tag can also support multiline statements in the same file. Statements can either be split using a ; at the end of the last line of the SQL or a ‘GO’ on its own on the line between the statements can be used. Multiline SQL statements are also supported and only a ; or GO statement will finish a statement, a new line is not enough. Files containing a single statement do not need to use a ; or GO.
The sql change can also contain comments of either of the following formats:
A multiline comment that starts with /* and ends with */. A single line comment starting with <space>–<space> and finishing at the end of the line. Note: By default it will attempt to split statements on a ‘;’ or ‘go’ at the end of lines. Because of this, if you have a comment or some other non-statement ending ‘;’ or ‘go’, don’t have it at the end of a line or you will get invalid SQL.
Name | Description |
---|---|
dbms | Logical expression of database type(s) on which the change must be applied. Valid database type names are listed on the supported databases page
It can be a comma separated list of multiple databases.
Or You can also specify that a change is NOT applicable to a particular database type by prefixing with ! . The keywords all and none are also available.@ v3.0E.g. 'h2, oracle' |
endDelimiter | Delimiter to apply to the end of the statement. Defaults to ';', may be set to ''.E.g. '\nGO' |
splitStatements | booleanSet to false to not have liquibase split statements on ;'s and GO's. Defaults to true if not setDefault: true |
[XML: text content] / sql | The SQL to executeE.g. 'insert into person (name) values ('Bob')'Note: the content of the tag in XML |
stripComments | booleanSet to true to remove any comments in the SQL before executing, otherwise false. Defaults to false if not set |
Name | Description |
---|---|
comment | E.g. 'What about Bob?' |
Database | Notes | Auto Rollback |
---|---|---|
DB2/LUW | Supported | No |
DB2/z | Supported | No |
Derby | Supported | No |
Firebird | Supported | No |
H2 | Supported | No |
HyperSQL | Supported | No |
INGRES | Supported | No |
Informix | Supported | No |
MariaDB | Supported | No |
MySQL | Supported | No |
Oracle | Supported | No |
PostgreSQL | Supported | No |
SQL Server | Supported | No |
SQLite | Supported | No |
Sybase | Supported | No |
Sybase Anywhere | Supported | No |