column

The column tag specifies information about columns you create or modify with Change Types like createTable, createIndex, addColumn, dropColumn, insert, and others. You can specify one or multiple columns in a single changeset.

Uses

Use the column tag to define the behavior of your table columns in different ways. For example, setting the defaultValue attribute on a column specifies its default value. Setting the value attribute sets all rows existing to the specified value without modifying the column default.

Some Change Type that interact with table columns, like addPrimaryKey, do not use the <column> tag. Instead, they use their own attributes like columnNames to refer to existing columns specified with the <column> tag.

Available attributes

Note: Because the <column> tag has multiple uses, not every attributes is valid in each context it is used in.

Attribute Description
name The name of the column.
type The column data type.
value Sets all fields in the column to the specified value. The value will be surrounded by quote marks. Nested quote marks will be escaped.
afterColumn

Controls the placement of a new column added with the addColumn Change Type.

Note: Only one of beforeColumn, afterColumn, or position is allowed.

autoIncrement The auto-increment column. Ignored on databases that do not support auto-increment or identity functionality.
beforeColumn

Controls the placement of a new column added with the addColumn Change Type.

Note: Only one of beforeColumn, afterColumn, or position is allowed.

computed Used if the value in name is a function rather than a column name.
defaultValue

The default value for fields in the column.

Note: If you don't set the first value, the defaultValueXXX is used in the order it appears.

defaultValueBoolean The default boolean value for fields in the column.
defaultValueComputed The default value that is returned from a function or procedure call. Contains the function to call.
defaultValueDate The default date and time value for column. The value is specified in one of the following forms: YYYY-MM-DD, hh:mm:ss, or YYYY-MM-DDThh:mm:ss.
defaultValueNumeric The default numeric value for fields in the column.
descending Defines whether a column is in descending order in the index if it is used in a createIndex command. Default value is false (ascending).
encoding The name of the encoding (specified in java.nio.Charset javadoc, e.g. "UTF-8") of the CLOB file (specified in valueClobFile) contents.

Note: This attribute is used only when valueClobFileattribute is specified. Otherwise, it is ignored.

incrementBy The value of each step by auto-increment. Ignored on databases that do not support auto-increment or identity functionality.
position

Controls the placement of a new column added with the addColumn Change Type.

Note: Only one of beforeColumn, afterColumn, or position is allowed.

remarks A short description of the column (column comment).
startWith The value auto-increment starts at. Ignored on databases that do not support auto-increment or identity functionality.
valueBlobFile

The path to a file whose contents will be written as a BLOB (binary large object).

The path to the changelog file location must be either absolute or relative. An example of an absolute path is: /usr/local/somefile.dat on Unix or c:\Directory\somefile.dat on Windows.

Note: Refer to java.io.File javadoc for the details of what to consider relative or absolute path.

valueBoolean The boolean value to set fields in the column to. The actual value string inserted depends on the database implementation.
valueClobFile

The path to a file whose contents will be written as a CLOB (character large object).

The path to the changelog file location must be either absolute or relative. An example of an absolute path is: /usr/local/somefile.dat on Unix or c:\Directory\somefile.dat on Windows.

Note: Refer to java.io.File javadoc for the details of what to consider relative or absolute path.

valueComputed The value that is returned from a function or procedure call. Contains the function to call.
valueDate The date and time value to set the column to. Accepts the following formats: YYYY-MM-DD, hh:mm:ss, or YYYY-MM-DDThh:mm:ss.
valueNumeric The numeric value to set fields in the column to. The value will not be escaped and will not be nested in quote marks.

To help make scripts database-independent, the following generic data types are automatically converted to the correct database implementation:

  • BIGINT
  • BLOB
  • BOOLEAN
  • CLOB
  • CURRENCY
  • DATE
  • DATETIME
  • TIME
  • UUID

Also, specifying a java.sql.Types.* type is converted to the correct type as well. For example:

  • java.sql.Types.TIMESTAMP
  • java.sql.Types.VARCHAR(255)

Available sub-tags

Tag Description
constraints Constraint definitions

Constraints sub-tag

The <constraints> tag contains information about constraints on the column.

Available attributes

Attribute Description
checkConstraint Defines whether to validate the defined check constraint. Default: database-dependent
deleteCascade Sets DELETE CASCADE.
deferrable Defines whether constraints are deferrable. Default: database-dependent
foreignKeyName The foreign key name.
initiallyDeferred Defines whether constraints are initially deferred. Default: database-dependent
notNullConstraintName The NOT NULL CONSTRAINT name.
nullable Defines whether the column is nullable. Default: database-dependent
primaryKey Defines whether the column is a primary key. Default: database-dependent
primaryKeyName The name of the primary key.
primaryKeyTablespace The tablespace to use for the defined primary key.
unique Defines whether a unique clause should be applied. Default: database-dependent
uniqueConstraintName The unique constraint name.
references The foreign key definition. ( This value is used as-is in the generated SQL so ensure all required quoting or other required syntax is being used. If you do not need to specify the exact SQL, use referencedTableName and referencedColumnNames instead)
referencedColumnNames The name of the column.
referencedTableCatalogName The name of the catalog.
referencedTableName The name of the table.
referencedTableSchemaName The name of the schema.
validateForeignKey Defines whether to validate the defined foreign key constraint. Default: database-dependent
validateNullable Defines whether to validate the defined not null constraint. Default: database-dependent
validatePrimaryKey Defines whether to validate the defined primary key constraint. Default: database-dependent
validateUnique Defines whether to validate the defined unique constraint. Default: database-dependent

Note: YAML and JSON changelogs using the column tag must nest it within a columns tag.

Related links