PostgreSQL Schema
aggregate
Attributes
Name | Required | Value |
---|---|---|
comment | false | string |
depends_on | false | List of object references |
initial_value | false | Aggregate initial value can be one of:
|
parallel | false |
|
schema | true | Object reference to |
state_func | true | Object reference to |
state_type | true | Aggregate state type can be one of: |
Blocks
aggregate.arg
aggregate.arg
attributes
Name | Required | Value |
---|---|---|
default | false | Aggregate argument default value can be one of:
|
mode | false | Aggregate argument mode can be one of:
|
type | true | Aggregate argument type can be one of: |
aggregate.arg
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
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
Name | Required | Value |
---|---|---|
comment | false | string |
name | false | string |
schema | true | Object reference to |
Blocks
composite.field
composite.field
attributes
Name | Required | Value |
---|---|---|
collate | false | string |
type | true | Field type can be one of: |
composite.field
constraints
Constraint | Value |
---|---|
Required | true |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
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
Name | Required | Value |
---|---|---|
comment | false | string |
default | false | Domain default value can be one of:
|
name | false | string |
null | false | bool |
schema | true | Object reference to |
type | true | Domain type can be one of: |
Blocks
domain.check
domain.check
attributes
Name | Required | Value |
---|---|---|
comment | false | string |
expr | true | string |
domain.check
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
enum
The enum
block describes an ENUM type in the schema.
enum "status" {
schema = schema.test
values = ["on", "off"]
}
Attributes
Name | Required | Value |
---|---|---|
comment | false | string |
name | false | string |
schema | true | Object reference to |
values | true | List of strings |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
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
Name | Required | Value |
---|---|---|
comment | false | string |
execute | true | Object reference to |
on | true | Event trigger on can be one of:
|
tags | false | List of strings |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
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 description | Required | Value |
---|---|---|
comment | false | string |
The | false | List of object reference to |
name | false | string |
schema | false | Object reference to |
version | false | string |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
function
The function
block describes a function in a database schema.
function "positive" {
schema = schema.public
lang = SQL
arg "v" {
type = integer
}
...
}
Attributes
Name | Required | Value |
---|---|---|
as | true | string |
comment | false | string |
depends_on | false | List of object references |
lang | true | Function language can be one of:
|
leakproof | false | bool |
parallel | false |
|
return | false | Function return type can be one of: |
return_set | false | Function return_set type can be one of: |
schema | true | Object reference to |
security | false |
|
strict | false | bool |
volatility | false |
|
Blocks
function.arg
function.arg
attributes
Name | Required | Value |
---|---|---|
default | false | Function argument default value can be one of:
|
mode | false | Function argument mode can be one of:
|
type | true | Function argument type can be one of: |
function.arg
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
function.return_table
function.return_table
blocks
function.return_table.column
function.return_table.column
attributes
Name | Required | Value |
---|---|---|
type | true | Function return_table column type can be one of: |
function.return_table.column
constraints
Constraint | Value |
---|---|
Required | true |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
function.return_table
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
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
Name | Required | Value |
---|---|---|
as | true | string |
comment | false | string |
depends_on | false | List of object references |
schema | true | Object reference to |
Blocks
materialized.column
materialized.column
attributes
Name | Required | Value |
---|---|---|
comment | false | string |
null | false | bool |
type | true | Column type can be one of: |
materialized.column
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
materialized.index
materialized.index
attributes
Name | Required | Value |
---|---|---|
columns | false | Index columns can be one of:
|
comment | false | string |
include | false | Index included columns can be one of:
|
nulls_distinct | false | bool |
page_per_range | false | int |
type | false | Index key type can be one of:
|
unique | false | bool |
where | false | string |
materialized.index
blocks
materialized.index.on
materialized.index.on
attributes
Name | Required | Value |
---|---|---|
column | false | Index columns can be one of:
|
desc | false | bool |
expr | false | string |
nulls_first | false | bool |
nulls_last | false | bool |
ops | false | Index operator class can be one of:
|
materialized.index.on
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [column, expr] , [nulls_last, nulls_first] |
materialized.index
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [columns, on] |
One of required sets | [columns, on] |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
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
Name | Required | Value |
---|---|---|
as | false |
|
check | false | string |
comment | false | string |
for | false |
|
on | true | Object reference to |
to | false | List of strings or/and |
using | false | string |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
procedure
The procedure
block describes a procedure in a database schema.
procedure "proc" {
schema = schema.public
lang = SQL
arg "a" {
type = integer
}
...
}
Attributes
Name | Required | Value |
---|---|---|
as | true | string |
comment | false | string |
depends_on | false | List of object references |
lang | true | Procedure language can be one of:
|
schema | true | Object reference to |
security | false |
|
Blocks
procedure.arg
procedure.arg
attributes
Name | Required | Value |
---|---|---|
default | false | Procedure argument default value can be one of:
|
mode | false | Procedure argument mode can be one of:
|
type | true | Procedure argument type can be one of: |
procedure.arg
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
schema
The schema
block describes a database schema.
schema "public" {
...
}
Attributes
Name | Required | Value |
---|---|---|
comment | false | string |
name | false | string |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
sequence
The sequence
block describes a sequence in a database schema.
sequence "name" {
schema = schema.public
type = int
increment = 3
min_value = 9
}
Attributes
Name | Required | Value |
---|---|---|
cache | false | int |
comment | false | string |
cycle | false | bool |
increment | false | int |
max_value | false | int |
min_value | false | int |
owner | false | Object reference to |
schema | true | Object reference to |
start | false | int |
type | false | Schema type |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
table
The table
block describes a table in a database schema.
table "users" {
schema = schema.public
column "id" {
type = int
}
...
}
Attributes
Name | Required | Value |
---|---|---|
comment | false | string |
depends_on | false | List of object references |
schema | true | Object reference to |
Blocks
table.check
table.check
attributes
Name | Required | Value |
---|---|---|
comment | false | string |
expr | true | string |
table.check
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
table.column
table.column
attributes
Name | Required | Value |
---|---|---|
as | false | string |
comment | false | string |
default | false | Column default value can be one of:
|
null | false | bool |
type | true | Column type can be one of: |
table.column
blocks
table.column.as
table.column.as
attributes
Name | Required | Value |
---|---|---|
expr | true | string |
type | false |
|
table.column.as
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
table.column.identity
table.column.identity
attributes
Name | Required | Value |
---|---|---|
generated | false |
|
increment | false | int |
start | false | int |
table.column.identity
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
table.column
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [as (attribute), as (block)] |
table.exclude
table.exclude
attributes
Name | Required | Value |
---|---|---|
comment | false | string |
deferrable | false |
|
include | false | Index included columns can be one of:
|
nulls_distinct | false | bool |
page_per_range | false | int |
type | false | Index key type can be one of:
|
where | false | string |
table.exclude
blocks
table.exclude.on
table.exclude.on
attributes
Name | Required | Value |
---|---|---|
column | false | Index columns can be one of:
|
desc | false | bool |
expr | false | string |
op | false | Exclude element operator can be one of:
|
table.exclude.on
constraints
Constraint | Value |
---|---|
Required | true |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [column, expr] |
table.exclude
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
table.foreign_key
table.foreign_key
attributes
Name | Required | Value |
---|---|---|
columns | true | Foreign key columns can be one of:
|
comment | false | string |
deferrable | false |
|
on_delete | false |
|
on_update | false |
|
ref_columns | true | Foreign key reference columns can be one of:
|
table.foreign_key
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
table.index
table.index
attributes
Name | Required | Value |
---|---|---|
columns | false | Index columns can be one of:
|
comment | false | string |
include | false | Index included columns can be one of:
|
nulls_distinct | false | bool |
page_per_range | false | int |
type | false | Index key type can be one of:
|
unique | false | bool |
where | false | string |
table.index
blocks
table.index.on
table.index.on
attributes
Name | Required | Value |
---|---|---|
column | false | Index columns can be one of:
|
desc | false | bool |
expr | false | string |
nulls_first | false | bool |
nulls_last | false | bool |
ops | false | Index operator class can be one of:
|
table.index.on
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [column, expr] , [nulls_last, nulls_first] |
table.index
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [columns, on] |
One of required sets | [columns, on] |
table.partition
table.partition
attributes
Name | Required | Value |
---|---|---|
columns | false | Partition columns can be one of:
|
type | true |
|
table.partition
blocks
table.partition.by
table.partition.by
attributes
Name | Required | Value |
---|---|---|
column | false | Partition columns can be one of:
|
expr | false | string |
table.partition.by
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [column, expr] |
table.partition
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
table.primary_key
table.primary_key
attributes
Name | Required | Value |
---|---|---|
columns | true | Primary key columns can be one of:
|
comment | false | string |
deferrable | false |
|
include | false | Primary key included columns can be one of:
|
page_per_range | false | int |
type | false | Index key type can be one of:
|
table.primary_key
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
table.row_security
table.row_security
attributes
Name | Required | Value |
---|---|---|
enabled | false | bool |
enforced | false | bool |
table.row_security
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
table.unique
table.unique
attributes
Name | Required | Value |
---|---|---|
columns | true | Index columns can be one of:
|
comment | false | string |
deferrable | false |
|
include | false | Index included columns can be one of:
|
nulls_distinct | false | bool |
page_per_range | false | int |
table.unique
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
trigger
The trigger
block describes a trigger on a table in a database schema.
trigger "trigger_orders_audit" {
on = table.orders
...
}
Attributes
Name | Required | Value |
---|---|---|
as | false | string |
comment | false | string |
constraint | false | bool |
deferrable | false |
|
for | false |
|
foreach | false |
|
from | false | Object reference to |
on | true | Trigger on can be one of: |
when | false | string |
Blocks
trigger.after
trigger.after
attributes
Name | Required | Value |
---|---|---|
delete | false | bool |
insert | false | bool |
truncate | false | bool |
update | false | bool |
update_of | false | Trigger update_of columns can be one of:
|
trigger.after
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [update, update_of] |
One of required sets | [insert, delete, truncate, update, update_of] |
trigger.before
trigger.before
attributes
Name | Required | Value |
---|---|---|
delete | false | bool |
insert | false | bool |
truncate | false | bool |
update | false | bool |
update_of | false | Trigger update_of columns can be one of:
|
trigger.before
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [update, update_of] |
One of required sets | [insert, delete, truncate, update, update_of] |
trigger.execute
trigger.execute
attributes
Name | Required | Value |
---|---|---|
args | false | List of strings |
function | false | Object reference to |
procedure | false | Object reference to |
trigger.execute
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [function, procedure] |
One of required sets | [function, procedure] |
trigger.instead_of
trigger.instead_of
attributes
Name | Required | Value |
---|---|---|
delete | false | bool |
insert | false | bool |
truncate | false | bool |
update | false | bool |
update_of | false | Trigger update_of columns can be one of:
|
trigger.instead_of
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
Mutually exclusive sets | [update, update_of] |
One of required sets | [insert, delete, truncate, update, update_of] |
trigger.referencing
trigger.referencing
attributes
Name | Required | Value |
---|---|---|
new_table | false | string |
old_table | false | string |
trigger.referencing
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | false |
Repeatable | true |
Allow unknown blocks | false |
Allow unknown attributes | false |
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
Name | Required | Value |
---|---|---|
as | true | string |
check_option | false |
|
comment | false | string |
depends_on | false | List of object references |
schema | true | Object reference to |
Blocks
view.column
view.column
attributes
Name | Required | Value |
---|---|---|
comment | false | string |
null | false | bool |
type | true | Column type can be one of: |
view.column
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
view.security
view.security
attributes
Name | Required | Value |
---|---|---|
barrier | false | bool |
invoker | false | bool |
view.security
constraints
Constraint | Value |
---|---|
Required | false |
Require Name | false |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |
One of required sets | [invoker, barrier] |
Constraints
Constraint | Value |
---|---|
Required | false |
Require Name | true |
Allow Qualifier | true |
Repeatable | false |
Allow unknown blocks | false |
Allow unknown attributes | false |