Skip to main content

PostgreSQL Schema

aggregate

Attributes

NameRequiredValue
commentfalsestring
depends_onfalse

List of object references

initial_valuefalse

Aggregate initial value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
parallelfalse

enum (SAFE, UNSAFE, RESTRICTED)

schematrue

Object reference to schema

state_functrue

Object reference to function

state_typetrue

Aggregate state type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table

Blocks

aggregate.arg

aggregate.arg attributes
NameRequiredValue
defaultfalse

Aggregate argument default value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
modefalse

Aggregate argument mode can be one of:

  1. string
  2. enum (IN, OUT, INOUT, VARIADIC)
typetrue

Aggregate argument type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
aggregate.arg constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

composite

The composite block describes a composite type in the schema.

composite "address" {
schema = schema.public
field "street" {
type = text
}
field "city" {
type = text
}
}

Attributes

NameRequiredValue
commentfalsestring
namefalsestring
schematrue

Object reference to schema

Blocks

composite.field

composite.field attributes
NameRequiredValue
collatefalsestring
typetrue

Field type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
composite.field constraints
ConstraintValue
Requiredtrue
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

domain

The domain block describes a DOMAIN type in the schema.

domain "us_postal_code" {
schema = schema.public
type = text
null = true
check "us_postal_code_check" {
expr = "..."
}
}

Attributes

NameRequiredValue
commentfalsestring
defaultfalse

Domain default value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
namefalsestring
nullfalsebool
schematrue

Object reference to schema

typetrue

Domain type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table

Blocks

domain.check

domain.check attributes
NameRequiredValue
commentfalsestring
exprtruestring
domain.check constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

enum

The enum block describes an ENUM type in the schema.

enum "status" {
schema = schema.test
values = ["on", "off"]
}

Attributes

NameRequiredValue
commentfalsestring
namefalsestring
schematrue

Object reference to schema

valuestrue

List of strings

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

event_trigger

The event_trigger block describes an event trigger in the database.

event_trigger "record_table_creation" {
on = ddl_command_start
tags = ["CREATE TABLE"]
execute = function.record_table_creation
}

Attributes

NameRequiredValue
commentfalsestring
executetrue

Object reference to function

ontrue

Event trigger on can be one of:

  1. string
  2. enum (ddl_command_start, ddl_command_end, table_rewrite, sql_drop)
tagsfalse

List of strings

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifierfalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

extension

The extension block describes an extension in the database.

extension "postgis" {
schema = schema.public
}
extension "pgcrypto" {
schema = schema.public
version = "1.3"
comment = "cryptographic functions"
}

Attributes

Name and descriptionRequiredValue
commentfalsestring

depends_on

The depends_on attribute specifies the extensions that this extension depends on.

false

List of object reference to extension

namefalsestring
schemafalse

Object reference to schema

versionfalsestring

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifierfalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

function

The function block describes a function in a database schema.

function "positive" {
schema = schema.public
lang = SQL
arg "v" {
type = integer
}
...
}

Attributes

NameRequiredValue
astruestring
commentfalsestring
depends_onfalse

List of object references

langtrue

Function language can be one of:

  1. string
  2. enum (SQL, PLpgSQL)
leakprooffalsebool
parallelfalse

enum (SAFE, UNSAFE, RESTRICTED)

returnfalse

Function return type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
return_setfalse

Function return_set type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
schematrue

Object reference to schema

securityfalse

enum (DEFINER, INVOKER)

strictfalsebool
volatilityfalse

enum (VOLATILE, STABLE, IMMUTABLE)

Blocks

function.arg

function.arg attributes
NameRequiredValue
defaultfalse

Function argument default value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
modefalse

Function argument mode can be one of:

  1. string
  2. enum (IN, OUT, INOUT, VARIADIC)
typetrue

Function argument type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
function.arg constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

function.return_table

function.return_table blocks

function.return_table.column

function.return_table.column attributes
NameRequiredValue
typetrue

Function return_table column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
function.return_table.column constraints
ConstraintValue
Requiredtrue
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
function.return_table constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[return, return_set, return_table]

materialized

The materialized block describes a materialized view in a database schema.

materialized "name" {
schema = schema.public
column "total" {
null = true
type = numeric
}
...
}

Attributes

NameRequiredValue
astruestring
commentfalsestring
depends_onfalse

List of object references

schematrue

Object reference to schema

Blocks

materialized.column

materialized.column attributes
NameRequiredValue
commentfalsestring
nullfalsebool
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
materialized.column constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

materialized.index

materialized.index attributes
NameRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
includefalse

Index included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nulls_distinctfalsebool
page_per_rangefalseint
typefalse

Index key type can be one of:

  1. string
  2. enum (BTREE, BRIN, HASH, GIN, GIST, GiST, SPGIST, SPGiST)
uniquefalsebool
wherefalsestring
materialized.index blocks

materialized.index.on

materialized.index.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
exprfalsestring
nulls_firstfalsebool
nulls_lastfalsebool
opsfalse

Index operator class can be one of:

  1. string
  2. Raw expression defined with sql("expr")
  3. enum (bit_minmax_ops, box_inclusion_ops, bpchar_bloom_ops, bpchar_minmax_ops, bytea_bloom_ops, bytea_minmax_ops, char_bloom_ops, char_minmax_ops, date_bloom_ops, date_minmax_multi_ops, date_minmax_ops, float4_bloom_ops, float4_minmax_multi_ops, float4_minmax_ops, float8_bloom_ops, float8_minmax_multi_ops, float8_minmax_ops, inet_bloom_ops, inet_inclusion_ops, inet_minmax_multi_ops, inet_minmax_ops, int2_bloom_ops, int2_minmax_multi_ops, int2_minmax_ops, int4_bloom_ops, int4_minmax_multi_ops, int4_minmax_ops, int8_bloom_ops, int8_minmax_multi_ops, int8_minmax_ops, interval_bloom_ops, interval_minmax_multi_ops, interval_minmax_ops, macaddr8_bloom_ops, macaddr8_minmax_multi_ops, macaddr8_minmax_ops, macaddr_bloom_ops, macaddr_minmax_multi_ops, macaddr_minmax_ops, name_bloom_ops, name_minmax_ops, numeric_bloom_ops, numeric_minmax_multi_ops, numeric_minmax_ops, oid_bloom_ops, oid_minmax_multi_ops, oid_minmax_ops, pg_lsn_bloom_ops, pg_lsn_minmax_multi_ops, pg_lsn_minmax_ops, range_inclusion_ops, text_bloom_ops, text_minmax_ops, tid_bloom_ops, tid_minmax_multi_ops, tid_minmax_ops, time_bloom_ops, time_minmax_multi_ops, time_minmax_ops, timestamp_bloom_ops, timestamp_minmax_multi_ops, timestamp_minmax_ops, timestamptz_bloom_ops, timestamptz_minmax_multi_ops, timestamptz_minmax_ops, timetz_bloom_ops, timetz_minmax_multi_ops, timetz_minmax_ops, uuid_bloom_ops, uuid_minmax_multi_ops, uuid_minmax_ops, varbit_minmax_ops, array_ops, bit_ops, bool_ops, bpchar_ops, bpchar_pattern_ops, bytea_ops, char_ops, cidr_ops, date_ops, enum_ops, float4_ops, float8_ops, inet_ops, int2_ops, int4_ops, int8_ops, interval_ops, jsonb_ops, macaddr8_ops, macaddr_ops, money_ops, multirange_ops, name_ops, numeric_ops, oid_ops, oidvector_ops, pg_lsn_ops, range_ops, record_image_ops, record_ops, text_ops, text_pattern_ops, tid_ops, time_ops, timestamp_ops, timestamptz_ops, timetz_ops, tsquery_ops, tsvector_ops, uuid_ops, varbit_ops, varchar_ops, varchar_pattern_ops, xid8_ops, array_ops, jsonb_ops, jsonb_path_ops, tsvector_ops, box_ops, circle_ops, inet_ops, multirange_ops, point_ops, poly_ops, range_ops, tsquery_ops, tsvector_ops, aclitem_ops, array_ops, bool_ops, bpchar_ops, bpchar_pattern_ops, bytea_ops, char_ops, cid_ops, cidr_ops, date_ops, enum_ops, float4_ops, float8_ops, inet_ops, int2_ops, int4_ops, int8_ops, interval_ops, jsonb_ops, macaddr8_ops, macaddr_ops, multirange_ops, name_ops, numeric_ops, oid_ops, oidvector_ops, pg_lsn_ops, range_ops, record_ops, text_ops, text_pattern_ops, tid_ops, time_ops, timestamp_ops, timestamptz_ops, timetz_ops, uuid_ops, varchar_ops, varchar_pattern_ops, xid8_ops, xid_ops, box_ops, inet_ops, kd_point_ops, poly_ops, quad_point_ops, range_ops, text_ops, gin_trgm_ops, gist_trgm_ops, btree_geography_ops, btree_geometry_ops, gist_geography_ops, gist_geometry_ops_2d, gist_geometry_ops_nd, gist_geometry_ops_3d, hash_geometry_ops, brin_geography_inclusion_ops, brin_geometry_inclusion_ops_2d, brin_geometry_inclusion_ops_3d, brin_geometry_inclusion_ops_4d, spgist_geography_ops_nd, spgist_geometry_ops_2d, spgist_geometry_ops_3d, spgist_geometry_ops_nd)
materialized.index.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[column, expr], [nulls_last, nulls_first]
materialized.index constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

policy

The policy block describes a row-level security policy for a table.

policy "policy_name" {
on = table.users
for = UPDATE
to = [PUBLIC]
check = "(name = ( SELECT name FROM allowed_names))"
}

Attributes

NameRequiredValue
asfalse

enum (PERMISSIVE, RESTRICTIVE)

checkfalsestring
commentfalsestring
forfalse

enum (ALL, SELECT, INSERT, UPDATE, DELETE)

ontrue

Object reference to table

tofalse

List of strings or/and enums (PUBLIC, CURRENT_ROLE, CURRENT_USER, SESSION_USER)

usingfalsestring

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifierfalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

procedure

The procedure block describes a procedure in a database schema.

procedure "proc" {
schema = schema.public
lang = SQL
arg "a" {
type = integer
}
...
}

Attributes

NameRequiredValue
astruestring
commentfalsestring
depends_onfalse

List of object references

langtrue

Procedure language can be one of:

  1. string
  2. enum (SQL, PLpgSQL)
schematrue

Object reference to schema

securityfalse

enum (DEFINER, INVOKER)

Blocks

procedure.arg

procedure.arg attributes
NameRequiredValue
defaultfalse

Procedure argument default value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
modefalse

Procedure argument mode can be one of:

  1. string
  2. enum (IN, OUT, INOUT, VARIADIC)
typetrue

Procedure argument type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
procedure.arg constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

schema

The schema block describes a database schema.

schema "public" {
...
}

Attributes

NameRequiredValue
commentfalsestring
namefalsestring

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifierfalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

sequence

The sequence block describes a sequence in a database schema.

sequence "name" {
schema = schema.public
type = int
increment = 3
min_value = 9
}

Attributes

NameRequiredValue
cachefalseint
commentfalsestring
cyclefalsebool
incrementfalseint
max_valuefalseint
min_valuefalseint
ownerfalse

Object reference to table.column

schematrue

Object reference to schema

startfalseint
typefalse

Schema type

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

table

The table block describes a table in a database schema.

table "users" {
schema = schema.public
column "id" {
type = int
}
...
}

Attributes

NameRequiredValue
commentfalsestring
depends_onfalse

List of object references

schematrue

Object reference to schema

Blocks

table.check

table.check attributes
NameRequiredValue
commentfalsestring
exprtruestring
table.check constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

table.column

table.column attributes
NameRequiredValue
asfalsestring
commentfalsestring
defaultfalse

Column default value can be one of:

  1. bool
  2. string
  3. number
  4. Raw expression defined with sql("expr")
nullfalsebool
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
table.column blocks

table.column.as

table.column.as attributes
NameRequiredValue
exprtruestring
typefalse

enum (STORED)

table.column.as constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

table.column.identity

table.column.identity attributes
NameRequiredValue
generatedfalse

enum (ALWAYS, BY_DEFAULT)

incrementfalseint
startfalseint
table.column.identity constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
table.column constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[as (attribute), as (block)]

table.exclude

table.exclude attributes
NameRequiredValue
commentfalsestring
deferrablefalse

enum (INITIALLY_IMMEDIATE, INITIALLY_DEFERRED)

includefalse

Index included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nulls_distinctfalsebool
page_per_rangefalseint
typefalse

Index key type can be one of:

  1. string
  2. enum (BTREE, BRIN, HASH, GIN, GIST, GiST, SPGIST, SPGiST)
wherefalsestring
table.exclude blocks

table.exclude.on

table.exclude.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
exprfalsestring
opfalse

Exclude element operator can be one of:

  1. string
  2. Raw expression defined with sql("expr")
table.exclude.on constraints
ConstraintValue
Requiredtrue
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[column, expr]
table.exclude constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

table.foreign_key

table.foreign_key attributes
NameRequiredValue
columnstrue

Foreign key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
deferrablefalse

enum (INITIALLY_IMMEDIATE, INITIALLY_DEFERRED)

on_deletefalse

enum (NO_ACTION, RESTRICT, CASCADE, SET_NULL, SET_DEFAULT)

on_updatefalse

enum (NO_ACTION, RESTRICT, CASCADE, SET_NULL, SET_DEFAULT)

ref_columnstrue

Foreign key reference columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
table.foreign_key constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

table.index

table.index attributes
NameRequiredValue
columnsfalse

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
includefalse

Index included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nulls_distinctfalsebool
page_per_rangefalseint
typefalse

Index key type can be one of:

  1. string
  2. enum (BTREE, BRIN, HASH, GIN, GIST, GiST, SPGIST, SPGiST)
uniquefalsebool
wherefalsestring
table.index blocks

table.index.on

table.index.on attributes
NameRequiredValue
columnfalse

Index columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
descfalsebool
exprfalsestring
nulls_firstfalsebool
nulls_lastfalsebool
opsfalse

Index operator class can be one of:

  1. string
  2. Raw expression defined with sql("expr")
  3. enum (bit_minmax_ops, box_inclusion_ops, bpchar_bloom_ops, bpchar_minmax_ops, bytea_bloom_ops, bytea_minmax_ops, char_bloom_ops, char_minmax_ops, date_bloom_ops, date_minmax_multi_ops, date_minmax_ops, float4_bloom_ops, float4_minmax_multi_ops, float4_minmax_ops, float8_bloom_ops, float8_minmax_multi_ops, float8_minmax_ops, inet_bloom_ops, inet_inclusion_ops, inet_minmax_multi_ops, inet_minmax_ops, int2_bloom_ops, int2_minmax_multi_ops, int2_minmax_ops, int4_bloom_ops, int4_minmax_multi_ops, int4_minmax_ops, int8_bloom_ops, int8_minmax_multi_ops, int8_minmax_ops, interval_bloom_ops, interval_minmax_multi_ops, interval_minmax_ops, macaddr8_bloom_ops, macaddr8_minmax_multi_ops, macaddr8_minmax_ops, macaddr_bloom_ops, macaddr_minmax_multi_ops, macaddr_minmax_ops, name_bloom_ops, name_minmax_ops, numeric_bloom_ops, numeric_minmax_multi_ops, numeric_minmax_ops, oid_bloom_ops, oid_minmax_multi_ops, oid_minmax_ops, pg_lsn_bloom_ops, pg_lsn_minmax_multi_ops, pg_lsn_minmax_ops, range_inclusion_ops, text_bloom_ops, text_minmax_ops, tid_bloom_ops, tid_minmax_multi_ops, tid_minmax_ops, time_bloom_ops, time_minmax_multi_ops, time_minmax_ops, timestamp_bloom_ops, timestamp_minmax_multi_ops, timestamp_minmax_ops, timestamptz_bloom_ops, timestamptz_minmax_multi_ops, timestamptz_minmax_ops, timetz_bloom_ops, timetz_minmax_multi_ops, timetz_minmax_ops, uuid_bloom_ops, uuid_minmax_multi_ops, uuid_minmax_ops, varbit_minmax_ops, array_ops, bit_ops, bool_ops, bpchar_ops, bpchar_pattern_ops, bytea_ops, char_ops, cidr_ops, date_ops, enum_ops, float4_ops, float8_ops, inet_ops, int2_ops, int4_ops, int8_ops, interval_ops, jsonb_ops, macaddr8_ops, macaddr_ops, money_ops, multirange_ops, name_ops, numeric_ops, oid_ops, oidvector_ops, pg_lsn_ops, range_ops, record_image_ops, record_ops, text_ops, text_pattern_ops, tid_ops, time_ops, timestamp_ops, timestamptz_ops, timetz_ops, tsquery_ops, tsvector_ops, uuid_ops, varbit_ops, varchar_ops, varchar_pattern_ops, xid8_ops, array_ops, jsonb_ops, jsonb_path_ops, tsvector_ops, box_ops, circle_ops, inet_ops, multirange_ops, point_ops, poly_ops, range_ops, tsquery_ops, tsvector_ops, aclitem_ops, array_ops, bool_ops, bpchar_ops, bpchar_pattern_ops, bytea_ops, char_ops, cid_ops, cidr_ops, date_ops, enum_ops, float4_ops, float8_ops, inet_ops, int2_ops, int4_ops, int8_ops, interval_ops, jsonb_ops, macaddr8_ops, macaddr_ops, multirange_ops, name_ops, numeric_ops, oid_ops, oidvector_ops, pg_lsn_ops, range_ops, record_ops, text_ops, text_pattern_ops, tid_ops, time_ops, timestamp_ops, timestamptz_ops, timetz_ops, uuid_ops, varchar_ops, varchar_pattern_ops, xid8_ops, xid_ops, box_ops, inet_ops, kd_point_ops, poly_ops, quad_point_ops, range_ops, text_ops, gin_trgm_ops, gist_trgm_ops, btree_geography_ops, btree_geometry_ops, gist_geography_ops, gist_geometry_ops_2d, gist_geometry_ops_nd, gist_geometry_ops_3d, hash_geometry_ops, brin_geography_inclusion_ops, brin_geometry_inclusion_ops_2d, brin_geometry_inclusion_ops_3d, brin_geometry_inclusion_ops_4d, spgist_geography_ops_nd, spgist_geometry_ops_2d, spgist_geometry_ops_3d, spgist_geometry_ops_nd)
table.index.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[column, expr], [nulls_last, nulls_first]
table.index constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

table.partition

table.partition attributes
NameRequiredValue
columnsfalse

Partition columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
typetrue

enum (RANGE, LIST, HASH)

table.partition blocks

table.partition.by

table.partition.by attributes
NameRequiredValue
columnfalse

Partition columns can be one of:

  1. Object reference to column
  2. Object reference to table.column
exprfalsestring
table.partition.by constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[column, expr]
table.partition constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

table.primary_key

table.primary_key attributes
NameRequiredValue
columnstrue

Primary key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
deferrablefalse

enum (INITIALLY_IMMEDIATE, INITIALLY_DEFERRED)

includefalse

Primary key included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
page_per_rangefalseint
typefalse

Index key type can be one of:

  1. string
  2. enum (BTREE, BRIN, HASH, GIN, GIST, GiST, SPGIST, SPGiST)
table.primary_key constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

table.row_security

table.row_security attributes
NameRequiredValue
enabledfalsebool
enforcedfalsebool
table.row_security constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

table.unique

table.unique attributes
NameRequiredValue
columnstrue

Index columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
deferrablefalse

enum (INITIALLY_IMMEDIATE, INITIALLY_DEFERRED)

includefalse

Index included columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
nulls_distinctfalsebool
page_per_rangefalseint
table.unique constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

trigger

The trigger block describes a trigger on a table in a database schema.

trigger "trigger_orders_audit" {
on = table.orders
...
}

Attributes

NameRequiredValue
asfalsestring
commentfalsestring
constraintfalsebool
deferrablefalse

enum (INITIALLY_IMMEDIATE, INITIALLY_DEFERRED)

forfalse

enum (ROW, STATEMENT)

foreachfalse

enum (ROW, STATEMENT)

fromfalse

Object reference to table

ontrue

Trigger on can be one of:

  1. Object reference to table
  2. Object reference to view
whenfalsestring

Blocks

trigger.after

trigger.after attributes
NameRequiredValue
deletefalsebool
insertfalsebool
truncatefalsebool
updatefalsebool
update_offalse

Trigger update_of columns can be one of:

  1. List of object reference to view.column
  2. List of object reference to table.column
trigger.after constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[update, update_of]
One of required sets[insert, delete, truncate, update, update_of]

trigger.before

trigger.before attributes
NameRequiredValue
deletefalsebool
insertfalsebool
truncatefalsebool
updatefalsebool
update_offalse

Trigger update_of columns can be one of:

  1. List of object reference to view.column
  2. List of object reference to table.column
trigger.before constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[update, update_of]
One of required sets[insert, delete, truncate, update, update_of]

trigger.execute

trigger.execute attributes
NameRequiredValue
argsfalse

List of strings

functionfalse

Object reference to function

procedurefalse

Object reference to procedure

trigger.execute constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[function, procedure]
One of required sets[function, procedure]

trigger.instead_of

trigger.instead_of attributes
NameRequiredValue
deletefalsebool
insertfalsebool
truncatefalsebool
updatefalsebool
update_offalse

Trigger update_of columns can be one of:

  1. List of object reference to view.column
  2. List of object reference to table.column
trigger.instead_of constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[update, update_of]
One of required sets[insert, delete, truncate, update, update_of]

trigger.referencing

trigger.referencing attributes
NameRequiredValue
new_tablefalsestring
old_tablefalsestring
trigger.referencing constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifierfalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[foreach, for], [before, after, instead_of], [as, execute]
One of required sets[before, after, instead_of], [as, execute]

view

The view block describes a view in a database schema.

view "clean_users" {
schema = schema.public
column "id" {
type = int
}
...
}

Attributes

NameRequiredValue
astruestring
check_optionfalse

enum (LOCAL, CASCADED)

commentfalsestring
depends_onfalse

List of object references

schematrue

Object reference to schema

Blocks

view.column

view.column attributes
NameRequiredValue
commentfalsestring
nullfalsebool
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
  3. Object reference to enum
  4. Object reference to domain
  5. Object reference to composite
  6. Object reference to table
view.column constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

view.security

view.security attributes
NameRequiredValue
barrierfalsebool
invokerfalsebool
view.security constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
One of required sets[invoker, barrier]

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifiertrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse