objectQuotingStrategy

The objectQuotingStrategy attribute is used to control how object names are quoted in the SQL files generated by Liquibase and used in calls to the database. You can specify it as an attribute of the <databaseChangeLog> tag in your changelog or in individual changesets.

Uses

The database treats unquoted object names in SQL as case-insensitive by default. However, if you prefer to use case-sensitive object names or are using a reserved word like "table" as an object name, you must quote the names.

In Liquibase, there are three possible values for the objectQuotingStrategy attribute:

  • LEGACY – The default value. Does not quote objects unless the database specifies that they must be quoted. This may include reserved words and names containing special characters or spaces. In PostgreSQL databases, mixed-case names are also quoted.
  • QUOTE_ALL_OBJECTS – Every object gets quoted. For example, person becomes "person".
  • QUOTE_ONLY_RESERVED_WORDS – The same logic as LEGACY, but without mixed-case objects in PostgreSQL databases.

Tip: Databases may add new reserved words over time. For example, key may work as a table name until a new version of your database reserves key. In a later release, Liquibase also marks key as reserved. When you upgrade Liquibase, you must ensure your scripts can handle the new keyword being quoted.

Limitations

Liquibase can only use objectQuotingStrategy with simple object names. Liquibase cannot quote arbitrary blocks of SQL that are defined in a <sql> tag. Instead, quote the objects directly in the SQL you're sending to Liquibase.

objectQuotingStrategy also does not work on SQL in the references attribute of the <constraints> tag. Instead, you can use referencedTableName and referencedColumnName to specify the foreign key reference.

Syntax

In a changelog:

databaseChangeLog:
    -  objectQuotingStrategy: QUOTE_ALL_OBJECTS
    -  changeSet:
        author: adrian
        id: 1
        changes:
        -  createTable:
            schemaName: proschema
            tableName: person
            columns:
            -  column:
                name: name
                type: varchar(255)

In a changeset:

- changeSet:
    author: adrian
    id: 1
    objectQuotingStrategy: QUOTE_ALL_OBJECTS
    changes:
    -  createTable:
        schemaName: proschema
        tableName: person
        columns:
        -  column:
            name: name
            type: varchar(255)

In a changelog:

{
"databaseChangeLog":[
  {
    "objectQuotingStrategy": "QUOTE_ALL_OBJECTS"
  },
  {
  "changeSet": {
    "author": "adrian",
    "id": "1",
    "changes": [
      {
      "createTable": {
        "schemaName": "proschema",
        "tableName": "person",
        "columns": [
        {
        "column": {
          "name": "name",
          "type": "varchar(255)"
                }
              }
            ]
          }
        }
      ]
    }
  }
}

In a changeset:

{
"changeSet": {
  "author": "adrian",
  "id": "1",
  "objectQuotingStrategy": "QUOTE_ALL_OBJECTS",
  "changes": [
    {
    "createTable": {
      "schemaName": "proschema",
      "tableName": "person",
      "columns": [
      {
      "column": {
        "name": "name",
        "type": "varchar(255)"
              }
            }
          ]
        }
      }
    ]
  }
}

In a changelog:

<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
    xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
    xmlns:pro="http://www.liquibase.org/xml/ns/pro"
    xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
        http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd
        http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd
        http://www.liquibase.org/xml/ns/pro http://www.liquibase.org/xml/ns/pro/liquibase-pro-latest.xsd"
    objectQuotingStrategy="QUOTE_ALL_OBJECTS">

In a changeset:

<changeSet author="adrian" id="1" objectQuotingStrategy="QUOTE_ALL_OBJECTS">
    <createTable schemaName="proschema" tableName="person">
        <column name="name" type="varchar(255)"/>
    </createTable>
</changeSet>