execute-sql

Last published July 28, 2025

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.

Syntax

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:

  • URL, driver [optional], and user authentication information such as username and password.

  • sql or sql-file parameter.

Tip: For more information about the options to store parameters in the Liquibase properties file, environment variables, or JAVA_OPTs, see the Integration guide.

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

Parameters

Global parameters

Attribute

Definition

Requirement

--output-file=<string>

File path to where the command output will be written: a CSV file that is the result of running a SELECT query. If not specified, output goes to STDOUT. See --output-file.

Optional

Command parameters

Attribute

Definition

Requirement

--sql=<string>

The SQL string to execute

Note: Columns display in the same order they are specified in the argument. If no columns are specified (For example select * <table_name>), then the output will display columns in the same order they are in the database.

Required

--sql-file=<string>

Specifies the file where SQL statements are stored

Required

--url=<string>

The JDBC database connection URL.

Required

--default-catalog-name=<string>

Name of the default catalog to use for the database connection

Optional

--default-schema-name=<string>

Name of the default schema to use for the database connection. If defaultSchemaName is set, then objects do not have to be fully qualified. This means you can refer to just mytable instead of myschema.mytable.

Note: In the properties file and JAVA_OPTS only: in 4.18.0 and earlier, specify this parameter using the syntax defaultSchemaName. In 4.19.0 and later, use the syntax liquibase.command.defaultSchemaName.

Note: In Liquibase 4.12.0 and later, you can use mixed-case schema names if you set --preserve-schema-case to true. However, in Liquibase 4.12.0–4.22.0, the Liquibase validator still throws a DatabaseException error if you specify a mixed-case value of defaultSchemaName. In 4.23.0 and later, the Liquibase validator accepts any casing.

Optional

--delimiter=<string>

The delimiter to use when executing SQL scripts

Optional

--driver=<string>

The JDBC driver class

Optional

--driver-properties-file=<string>

The JDBC driver properties file

Optional

--password=<string>

Password to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

--username=<string>

Username to connect to the target database.

Tip: It is a best practice to store sensitive data in a Secrets Management tool with Liquibase Pro.

Optional

Liquibase Version: 4.9.1 Output of select * from databasechangelog: AUTHOR | COMMENTS | CONTEXTS | DATEEXECUTED | DEPLOYMENT_ID | DESCRIPTION | EXECTYPE | FILENAME | ID | LABELS | LIQUIBASE | MD5SUM | ORDEREXECUTED | TAG | liquibase | | null | 2022-05-13 12:02:12.125792 | 2464932010 | empty | EXECUTED | liquibase-internal | 1652464932094 | null | 4.9.1 | 8:d41d8cd98f00b204e9800998ecf8427e | 1 | version1 | other.dev | example comment | example-context | 2022-05-13 12:17:30.818119 | 2465850648 | sql | EXECUTED | example-changelog.sql | 3 | example-label | 4.9.1 | 8:98b5f38170a3749834d15d3361fc6d9b | 4 | version1 | Liquibase command 'execute-sql' was executed successfully.