execute-sql

Tip: The command uses syntax for Liquibase 4.4 and later. For earlier versions, use a camel case syntax and the following CLI order: [command parameters] [command] [global parameters]. To find the previous format of the command, run the liquibase --help command and refer to the deprecated version.

The execute-sql command executes a SQL string or file.

Uses

Use the execute-sql command to directly run SQL queries without changing and applying changelog files with changesets. An example of using the execute-sql command is to check the database data or make unplanned changes when you run Liquibase in automation.

Compared with other database query tools, the execute-sql command runs with the credentials and configuration you already have in Liquibase without any need to set up another tool. If statements run correctly in your database CLI but fail in Liquibase, running exploratory statements through execute-sql might help you find differences in permission configurations, connection setup, and SQL run in the database CLI or database-native SQL.

Note: The command does not affect the DATABASECHANGELOG table because the table is associated with changesets and tracks which changesets have been run. Liquibase recommends handling your changes with execute-sql only on rare occasions to not lose their traceability.

Running the execute-sql command

To run the execute-sql command, specify the following parameters in the Liquibase properties file, environment variables, or the command prompt while running the command:

Note: For more information about the options to store parameters, see Specifying Properties in a Connection Profile, Liquibase Environment Variables, and JAVA_OPTS Environment Variable. To find the format of a parameter, see Command Parameters.

Run the execute-sql command with the SQL string:

liquibase execute-sql --sql="select * from databasechangelog"

Run the execute-sql command with the SQL file:

liquibase execute-sql --sql-file=path/to/file.sql

Note: You can also specify --delimiter=/. The default value for delimiter is ;, which will work as long as you do not have stored logic.

execute-sql command parameters

Tip: All commands and parameters use the --kebab-case format in the CLI environment. This is the format Liquibase recommends for best results. If your preference is camelCase, it will still work in the CLI.

Parameter Definition Requirement
--url

The JDBC database connection URL

Required
--sql

The SQL string to execute

Required
--sql-file

The SQL file with a script to execute

Required
--username*

The database username

Required*
--password*

The database password

Required*
--default-catalog-name

The default catalog name to use for the database connection

Optional
--default-schema-name

The default schema name to use for the database connection

Optional
--delimiter

The delimiter to use when executing SQL scripts

Optional
--driver

The JDBC driver class

Optional
--driver-properties-file

The JDBC driver properties file

Optional

Note: The username and password attributes are not required for connections and systems which use alternate means of authentication.