PostgreSQL Schema
aggregate
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 | Aggregate state function can be one of:
|
state_type | true | Aggregate state type can be one of: |
aggregate 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 |
aggregate constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., aggregate "name" ) | true |
Allow Qualifier (e.g., aggregate "schema" "name" ) | true |
| Repeatable | true |
cast
The cast block describes a type cast in the database.
# Binary coercion cast (WITHOUT FUNCTION)
cast {
source = text
target = composite.my_type
}
# I/O conversion cast (WITH INOUT)
cast {
source = int4
target = composite.my_type
with = INOUT
}
# Function-based cast (WITH FUNCTION)
cast {
source = int4
target = composite.my_type
with = function.int4_to_my_type
as = IMPLICIT
}
cast attributes
| Name | Required | Value |
|---|---|---|
as | false |
|
source | true | Cast source type can be one of: |
target | true | Cast target type can be one of: |
with | false | Cast method (INOUT, function reference, or function expression) can be one of:
|
cast constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
collation
The collation block describes a collation in the schema.
collation "french" {
schema = schema.public
locale = "fr-x-icu"
provider = icu
}
collation "german" {
schema = schema.public
from = "german_phonebook"
}
collation attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
deterministic | false | bool |
lc_collate | false | string |
lc_ctype | false | string |
locale | false | string |
name | false | string |
provider | false | Collation provider can be one of:
|
rules | false | string |
schema | true | Object reference to |
version | false | string |
collation constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., collation "name" ) | true |
Allow Qualifier (e.g., collation "schema" "name" ) | true |
composite
The composite block describes a composite type in the schema.
composite "address" {
schema = schema.public
field "street" {
type = text
}
field "city" {
type = text
}
}
composite attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
name | false | string |
schema | true | Object reference to |
composite blocks
composite.field
composite.field attributes
| Name | Required | Value |
|---|---|---|
collate | false | Field collation can be one of:
|
type | true | Field type can be one of: |
composite.field constraints
| Constraint | Value |
|---|---|
| Required | true |
Require Name (e.g., composite.field "name" ) | true |
composite constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., composite "name" ) | true |
Allow Qualifier (e.g., composite "schema" "name" ) | true |
data
The data block defines seed/lookup data for a table.
data {
table = table.countries
rows = [
{ code = "US", name = "United States" },
{ code = "CA", name = "Canada" },
]
}
data attributes
| Name | Required | Value |
|---|---|---|
rows | true | Any value |
table | true | Object reference to |
data constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
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 = "..."
}
}
domain 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: |
domain 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 |
domain constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., domain "name" ) | true |
Allow Qualifier (e.g., domain "schema" "name" ) | true |
enum
The enum block describes an ENUM type in the schema.
enum "status" {
schema = schema.test
values = ["on", "off"]
}
enum attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
name | false | string |
schema | true | Object reference to |
values | true | List of strings |
enum constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., enum "name" ) | true |
Allow Qualifier (e.g., enum "schema" "name" ) | true |
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
}
event_trigger 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 |
event_trigger constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., event_trigger "name" ) | true |
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"
}
extension 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 |
extension constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., extension "name" ) | true |
foreign_table
foreign_table attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
depends_on | false | List of object references |
options | false | map |
replica_identity | false |
|
schema | true | Object reference to |
server | true | The reference or a name of an existing foreign server to use for the foreign table can be one of:
|
foreign_table blocks
foreign_table.check
foreign_table.check attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
expr | true | string |
foreign_table.check constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
foreign_table.column
foreign_table.column attributes
| Name | Required | Value |
|---|---|---|
as | false | string |
collate | false | Column collation can be one of:
|
comment | false | string |
null | false | bool |
options | false | map |
type | true | Column type can be one of: |
foreign_table.column blocks
foreign_table.column.as
foreign_table.column.as attributes
| Name | Required | Value |
|---|---|---|
expr | true | string |
type | false |
|
foreign_table.column constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., foreign_table.column "name" ) | true |
| Mutually exclusive sets | [as (attribute), as (block)] |
foreign_table constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., foreign_table "name" ) | true |
Allow Qualifier (e.g., foreign_table "schema" "name" ) | true |
function
The function block describes a function in a database schema.
function "positive" {
schema = schema.public
lang = SQL
arg "v" {
type = integer
}
...
}
function 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 |
|
function 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 |
function.config_params
The config_params block describes the configuration parameters to be set when the function is entered.
config_params {
search_path = "public"
work_mem = "64MB"
client_min_messages = "warning"
// Other custom configuration parameters.
}
function.config_params attributes
| Name | Required | Value |
|---|---|---|
schema | false | string |
search_path | false | string |
statement_timeout | false | string |
work_mem | false | string |
function.config_params constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown attributes | true |