Skip to content

Table

Defines a table

Properties

Property Type Required Description
name string yes The table name.
schema string yes The schema to create the table in.
owner string The role name that owns the table.
sql string User-provided raw SQL snippet.
unlogged boolean If specified, the table is created as an unlogged table. Data written to unlogged tables is not written to the write-ahead log, which makes them considerably faster than ordinary tables. However, they are not crash-safe: an unlogged table is automatically truncated after a crash or unclean shutdown.
from_type string Creates a typed table, which takes its structure from the specified composite type (name optionally schema-qualified).
parents array of string A list of tables from which the new table automatically inherits all columns. Parent tables can be plain tables or foreign tables.
like_table object Specifies a table from which the new table automatically copies all column names, their data types, and their not-null constraints.
columns array of column Defines the columns in the table.
column_defaults array of object Defaults on columns the table does not declare itself. An inheritance child inherits its parent's columns, so it has no column entry to carry a default; pg_dump writes those as a separate ALTER TABLE ONLY <child> ALTER COLUMN <column> SET DEFAULT .... A default on a column the table does declare belongs on the column instead.
primary_key string | array of string | object The PRIMARY KEY constraint specifies that a column or columns of a table can contain only unique (non-duplicate), non-null values. Only one primary key can be specified for a table. For primary keys without included columns, this value can be a list of column names. Otherwise it's an object with a columns and an include attribute.
indexes array of index An array of indexes on the table.
check_constraints array of object Table Check Constraints.
not_null_constraints array of object A NOT NULL constraint written at the table level rather than on the column (PostgreSQL 18 and later). pg_dump emits this form only for a column the table inherits rather than declares, since such a table has no column entry to carry nullable: false. Omit name when the constraint carries the name PostgreSQL generates by default, <table>_<column>_not_null.
unique_constraints array of (array of string | string | object) The UNIQUE constraint specifies that a group of one or more columns of a table can contain only unique values. The behavior of the unique table constraint is the same as that for column constraints, with the additional capability to span multiple columns. For the purpose of a unique constraint, null values are not considered equal. Each unique table constraint must name a set of columns that is different from the set of columns named by any other unique or primary key constraint defined for the table. (Otherwise it would just be the same constraint listed twice.) When establishing a unique constraint for a multi-level partition hierarchy, all the columns in the partition key of the target partitioned table, as well as those of all its descendant partitioned tables, must be included in the constraint definition. Adding a unique constraint will automatically create a unique btree index on the column or group of columns used in the constraint. The optional clause INCLUDE adds to that index one or more columns on which the uniqueness is not enforced. Note that although the constraint is not enforced on the included columns, it still depends on them. Consequently, some operations on these columns (e.g. DROP COLUMN) can cause cascaded constraint and index deletion. For unique constraints without included columns, this value can be a list of column names. Otherwise it's an object with a columns and an include attribute.
foreign_keys array of foreign_key An array of foreign keys on the table.
constraint_comments object Comments on the table's primary key, unique, check, foreign key and NOT NULL constraints, by constraint name. An exclusion constraint keeps its comment on itself.
exclude_constraints array of object An array of exclusion constraints (EXCLUDE): no two rows may have every element compare true under its operator.
triggers array of trigger An array of triggers on the table.
rules array of rule An array of rewrite rules on the table.
row_level_security object Whether row-level security is enabled and forced on the table. When absent, deploy does not manage the table's row security, and does not manage its policies unless policies is given. When present, policies is the complete list: an absent list means the table has no policies.
replica_identity DEFAULT | FULL | NOTHING | object What logical replication records to identify an updated or deleted row: FULL (the whole row), NOTHING, or a unique index given as {index: name}. Absent is DEFAULT, the primary key.
policies array of policy An array of row-level security policies on the table.
partition object Defines table partitioning behavior.
partitions array of object Define partitions of the table.
access_method string Specifies the table access method to use to store the contents for the new table; the method needs be an access method of type TABLE.
storage_parameters object Storage parameter settings for the table. A toast. prefix targets the table's TOAST table instead of the table itself.
tablespace string Specifies the name of the tablespace in which the new table is to be created.
index_tablespace string This clause allows selection of the tablespace in which the index associated with a UNIQUE, PRIMARY KEY, or EXCLUDE constraint will be created. If not specified, default_tablespace is consulted.
server string Used to specify the server if this is a foreign table.
options object Foreign table OPTIONS as an open key/value map; the available keys depend on the foreign data wrapper (e.g. postgres_fdw uses schema_name and table_name, file_fdw uses filename and format).
comment string An optional comment about the table.
dependencies dependencies Database objects this object is dependent upon.

like_table

Specifies a table from which the new table automatically copies all column names, their data types, and their not-null constraints.

Property Type Required Description
name string yes The table to copy.
include_comments boolean Include comments when creating the new table.
include_constraints boolean Include constraints.
include_defaults boolean Include defaults.
include_generated boolean Include generated expressions.
include_identity boolean Include identity specifications.
include_indexes boolean Include indexes.
include_statistics boolean Include extended statistics.
include_storage boolean Include storage settings.
include_all boolean Include all options (comments, constraints, defaults, generated, identity, indexes, statistics, and storage).

Mutually exclusive forms

Exactly one of these must hold:

  • include_comments, without include_all
  • include_constraints, without include_all
  • include_defaults, without include_all
  • include_generated, without include_all
  • include_identity, without include_all
  • include_indexes, without include_all
  • include_statistics, without include_all
  • include_storage, without include_all
  • include_all, without include_comments or include_constraints or include_defaults or include_generated or include_identity or include_indexes or include_statistics or include_storage

column_defaults[]

Property Type Required Description
column string yes Column Name.
default boolean | integer | number | string yes Default Value.

primary_key

Property Type Required Description
name string The constraint name, kept only when it is not the one PostgreSQL generates.
columns array yes The list of columns that provide the uniqueness. Minimum items: 1.
include array of string Use to provide a list of non-key columns to provide in the primary key index.
without_overlaps boolean Makes the constraint temporal (PostgreSQL 18+). WITHOUT OVERLAPS applies to the last column, which must be a range or multirange: rows may share the other column values as long as their ranges do not overlap.

check_constraints[]

Specifies an expression producing a Boolean result which new or updated rows must satisfy for an insert or update operation to succeed.

Property Type Required Description
name string The name PostgreSQL knows the constraint by.
expression string The boolean expression rows must satisfy, as it appears inside CHECK (...).
enforced boolean false renders NOT ENFORCED (PostgreSQL 18+), which stops the constraint being checked. PostgreSQL records a not-enforced constraint as not validated as well. Absent means enforced, the default.
not_valid boolean true renders NOT VALID: rows already in the table were never checked, only new ones are. The state holds only when the constraint is added with ALTER TABLE, so the build writes it that way. Absent means valid, the default.

not_null_constraints[]

Property Type Required Description
name string
column string yes
no_inherit boolean Whether the constraint is not inherited by this table's own descendants.
not_valid boolean true renders NOT VALID: rows already in the table were never checked, only new ones are. The state holds only when the constraint is added with ALTER TABLE, so the build writes it that way. Absent means valid, the default.

exclude_constraints[]

Property Type Required Description
name string yes Name.
method string The index access method, such as gist or btree.
elements array of object yes Each column or expression, with the operator it is compared with. Minimum items: 1.
include array of string Included Columns.
where string Only rows that satisfy this expression are compared.
deferrable boolean Deferrable.
initially_deferred boolean Initially Deferred.
comment string Comment.

row_level_security

Whether row-level security is enabled and forced on the table. When absent, deploy does not manage the table's row security, and does not manage its policies unless policies is given. When present, policies is the complete list: an absent list means the table has no policies.

Property Type Required Description
enabled boolean yes ENABLE ROW LEVEL SECURITY.
forced boolean FORCE ROW LEVEL SECURITY: the policies apply to the table owner too.

replica_identity

Property Type Required Description
index string yes Index.

partition

Defines table partitioning behavior

Property Type Required Description
type HASH | LIST | RANGE yes Partition Type.
columns string | array of string | object yes Defines the columns that are indexed.

partitions[]

Defines a partition of the table

Property Type Required Description
schema string yes The schema to create the table in.
name string yes The table name.
default boolean Indicates that the partition is the default partition.
for_values_in array of (boolean | integer | number | string) Used in LIST partitioning.
for_values_from integer | number | string Used in RANGE partitioning.
for_values_to integer | number | string Used in RANGE partitioning.
for_values_with string Used in HASH partitioning.
comment string An optional comment about the partition.

Mutually exclusive forms

Exactly one of these must hold:

  • default, without for_values_in or for_values_from or for_values_to or for_values_with
  • for_values_in, without default or for_values_from or for_values_to or for_values_with
  • for_values_from and for_values_to, without default or for_values_in or for_values_with
  • for_values_with, without default or for_values_in or for_values_from or for_values_to

Mutually exclusive forms

Exactly one of these must hold:

  • sql
  • server

No other properties are accepted.


Source: schemata/table.yml · Resolved JSON Schema: table.json