ClickHouse Schema
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 |
dictionary
The dictionary block describes a dictionary in a database schema.
dictionary "name" {
schema = schema.public
source = sql("CLICKHOUSE(TABLE)")
layout = sql("HASH()")
key "id" {
type = UInt64
}
attribute "name" {
type = String
}
lifetime {
min = 0
max = 0
}
...
}
dictionary attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
depends_on | false | List of object references |
layout | true | Raw expression defined with |
schema | true | Object reference to |
settings | false | map |
source | true | Raw expression defined with |
dictionary blocks
dictionary.attribute
dictionary.attribute attributes
| Name | Required | Value |
|---|---|---|
default | false | Column default expression can be one of:
|
null | false | bool |
type | true | Attribute type can be one of:
|
dictionary.attribute constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., dictionary.attribute "name" ) | true |
dictionary.key
dictionary.key attributes
| Name | Required | Value |
|---|---|---|
default | false | Column default expression can be one of:
|
null | false | bool |
type | true | Attribute type can be one of:
|
dictionary.key constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., dictionary.key "name" ) | true |
dictionary.lifetime
dictionary.lifetime attributes
| Name | Required | Value |
|---|---|---|
max | true | int |
min | true | int |
dictionary constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., dictionary "name" ) | true |
Allow Qualifier (e.g., dictionary "schema" "name" ) | true |
function
The function block describes a ClickHouse User-Defined Function (UDF).
function "plus_one" {
as = "(x) -> x + 1"
}
A WASM UDF sets lang and describes its module instead of an as body.
function "wasm_numbers" {
lang = WASM
returns = UInt32
module = wasm_module.math_module
source = "sub"
abi = ROW_DIRECT
deterministic = true
hash = "a957...d488"
settings = {
serialization_format = "MsgPack"
webassembly_udf_enable_fuel = 1
}
arg "a" {
type = UInt32
}
arg "b" {
type = UInt32
}
}
function attributes
| Name | Required | Value |
|---|---|---|
abi | false |
|
as | false | string |
deterministic | false | bool |
hash | false | string |
lang | false |
|
module | false | Module name or reference can be one of:
|
returns | false | Return type can be one of:
|
settings | false | map |
source | false | string |
function blocks
function.annotation
function.annotation constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown blocks | true |
| Allow unknown attributes | true |
function.arg
function.arg attributes
| Name | Required | Value |
|---|---|---|
type | true | Argument type can be one of:
|
function.arg constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
function constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., function "name" ) | true |
| Mutually exclusive sets | [as, lang] |
| One of required sets | [as, lang] |
materialized
The materialized block describes a materialized view in a database schema.
materialized "name" {
schema = schema.public
column "total" {
null = true
type = numeric
}
...
}
materialized attributes
| Name | Required | Value |
|---|---|---|
as | true | string |
comment | false | string |
definer | false | User or role that defines the view can be one of:
|
depends_on | false | List of object references |
engine | false | Table engine can be one of:
|
populate | false | bool |
schema | true | Object reference to |
security | false |
|
to | false | Define structure of view can be one of: |
materialized blocks
materialized.annotation
materialized.annotation constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown blocks | true |
| Allow unknown attributes | true |
materialized.column
materialized.column attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
null | false | bool |
type | true | Column type can be one of:
|
materialized.column blocks
materialized.column.annotation
materialized.column.annotation constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown blocks | true |
| Allow unknown attributes | true |
materialized.column constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., materialized.column "name" ) | true |
materialized.primary_key
materialized.primary_key attributes
| Name | Required | Value |
|---|---|---|
columns | false | Primary key columns can be one of:
|
comment | false | string |
materialized.primary_key blocks
materialized.primary_key.on
materialized.primary_key.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Primary key column can be one of:
|
expr | false | string |
materialized.primary_key.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
materialized.primary_key constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
materialized.refresh
The refresh block describes the refresh settings for a materialized view.
materialized "name" {
schema = schema.public
as = sql("SELECT * FROM table")
refresh {
expr = "EVERY 1 MINUTE"
append = true
depends_on = [materialized.other_view]
settings = {
refresh_retries = 4
}
}
materialized.refresh attributes
| Name | Required | Value |
|---|---|---|
append | false | bool |
depends_on | false | List of object reference to |
expr | true | string |
settings | false | map |
materialized.sort
materialized.sort attributes
| Name | Required | Value |
|---|---|---|
columns | false | List of object reference to |
materialized.sort blocks
materialized.sort.on
materialized.sort.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Object reference to |
expr | false | string |
materialized.sort.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
materialized.sort constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
materialized constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., materialized "name" ) | true |
Allow Qualifier (e.g., materialized "schema" "name" ) | true |
| Mutually exclusive sets | [to, engine], [to, populate] |
| One of required sets | [to, engine] |
named_collection
The named_collection block describes a ClickHouse named collection (key-value store).
named_collection "my_conn" {
item "host" {
value = "127.0.0.1"
}
item "port" {
value = 5432
}
item "user" {
value = "admin"
}
item "use_ssl" {
value = 1
}
}
named_collection blocks
named_collection.item
named_collection.item attributes
| Name | Required | Value |
|---|---|---|
value | true | Any value |
named_collection.item constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
named_collection constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., named_collection "name" ) | true |
permission
The permission block describes permissions (privileges) granted on database objects.
permission {
to = "user1"
for = table.users
privileges = [SELECT]
}
permission {
to = "admin"
for = schema.public
privileges = [ALL]
grantable = true
}
permission attributes
| Name | Required | Value |
|---|---|---|
for | true | Permission target resource can be one of:
|
grantable | false | bool |
privileges | true | List of strings or/and |
to | true | Role or user can be one of: |
permission constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
policy
The policy block describes a ClickHouse row-level security policy.
policy "filter_tenant" {
schema = schema.public
on = table.users
using = "tenant_id = 1"
to = [role.admin]
restrictive = true
}
policy attributes
| Name | Required | Value |
|---|---|---|
on | true | Table or view the policy applies to can be one of:
|
restrictive | false | bool |
to | false | List of values, where each can be one of: |
to_all | false | bool |
to_all_except | false | List of values, where each can be one of: |
using | false | string |
policy constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., policy "name" ) | true |
Allow Qualifier (e.g., policy "schema" "name" ) | true |
| Mutually exclusive sets | [to, to_all, to_all_except] |
| One of required sets | [to, to_all, to_all_except] |
role
The role block describes a database role.
role "admin" {
comment = "Admin role"
member_of = [role.viewer]
}
role attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
member_of | false | List of object references |
storage | false | string |
role blocks
role.settings_profile
role.settings_profile attributes
| Name | Required | Value |
|---|---|---|
inherit | false | List of values, where each can be one of:
|
role.settings_profile blocks
role.settings_profile.setting
role.settings_profile.setting attributes
| Name | Required | Value |
|---|---|---|
max | false | Any value |
min | false | Any value |
value | true | Any value |
writability | false | Writability constraint can be one of:
|
role.settings_profile.setting constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
role constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., role "name" ) | true |
| Repeatable | true |
schema
The schema block describes a database schema.
schema "public" {
...
}
schema attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
engine | false | Schema engine can be one of:
|
name | false | string |
schema blocks
schema.annotation
schema.annotation constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown blocks | true |
| Allow unknown attributes | true |
schema constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., schema "name" ) | true |
settings_profile
The settings_profile block describes a ClickHouse settings profile (realm-level access entity).
settings_profile "readonly" {
setting "max_memory_usage" {
value = 10000000000
writability = "CONST"
}
inherit = ["default"]
to = [role.analyst]
}
settings_profile attributes
| Name | Required | Value |
|---|---|---|
inherit | false | List of values, where each can be one of:
|
to | false | List of values, where each can be one of: |
to_all | false | bool |
to_all_except | false | List of values, where each can be one of: |
settings_profile blocks
settings_profile.setting
settings_profile.setting attributes
| Name | Required | Value |
|---|---|---|
max | false | Any value |
min | false | Any value |
value | true | Any value |
writability | false | Writability constraint can be one of:
|
settings_profile.setting constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
settings_profile constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., settings_profile "name" ) | true |
| Mutually exclusive sets | [to, to_all, to_all_except] |
table
The table block describes a table in a database schema.
table "users" {
schema = schema.public
column "id" {
type = int
}
...
}
table attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
depends_on | false | List of object references |
engine | false | Table engine can be one of:
|
renamed_from | false | string |
schema | true | Object reference to |
settings | false | map |
ttl | false | Column ttl can be one of:
|
table blocks
table.annotation
table.annotation constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown blocks | true |
| Allow unknown attributes | true |
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 |
table.column
table.column attributes
| Name | Required | Value |
|---|---|---|
codec | false | Column codec can be one of:
|
comment | false | string |
default | false | Column default expression can be one of:
|
default_kind | false | Column default kind can be one of:
|
null | false | bool |
renamed_from | false | string |
ttl | false | Column ttl can be one of:
|
type | true | Column type can be one of:
|
table.column blocks
table.column.annotation
table.column.annotation constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown blocks | true |
| Allow unknown attributes | true |
table.column constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., table.column "name" ) | true |
| Repeatable | true |
table.engine.TimeSeries
table.engine.TimeSeries attributes
| Name | Required | Value |
|---|---|---|
data | false | Object reference to |
metrics | false | Object reference to |
tags | false | Object reference to |
table.index
table.index attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
granularity | false | int |
type | true | Index type can be one of:
|
table.index blocks
table.index.on
table.index.on attributes
| Name | Required | Value |
|---|---|---|
expr | true | string |
table.index.on constraints
| Constraint | Value |
|---|---|
| Required | true |
| Require Name | false |
table.index constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., table.index "name" ) | true |
table.partition
table.partition attributes
| Name | Required | Value |
|---|---|---|
columns | false | List of object reference to |
table.partition blocks
table.partition.on
table.partition.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Object reference to |
expr | false | string |
table.partition.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
table.partition constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
table.primary_key
table.primary_key attributes
| Name | Required | Value |
|---|---|---|
columns | false | Primary key columns can be one of:
|
comment | false | string |
table.primary_key blocks
table.primary_key.on
table.primary_key.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Primary key column can be one of:
|
expr | false | string |
table.primary_key.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
table.primary_key constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
table.projection
The projection block describes a projection for a table
table "name" {
schema = schema.public
projection "name" {
as = "SELECT * FROM table WHERE condition"
}
projection "another" {
as = "SELECT * FROM table WHERE another_condition"
}
}
table.projection attributes
| Name | Required | Value |
|---|---|---|
as | true | string |
table.projection constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
table.sort
table.sort attributes
| Name | Required | Value |
|---|---|---|
columns | false | List of object reference to |
table.sort blocks
table.sort.on
table.sort.on attributes
| Name | Required | Value |
|---|---|---|
column | false | Object reference to |
expr | false | string |
table.sort.on constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
| Mutually exclusive sets | [column, expr] |
| One of required sets | [column, expr] |
table.sort constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Mutually exclusive sets | [columns, on] |
| One of required sets | [columns, on] |
table constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., table "name" ) | true |
Allow Qualifier (e.g., table "schema" "name" ) | true |
user
The user block describes a database user.
user "john" {
comment = "John Doe"
member_of = [role.admin]
}
user attributes
| Name | Required | Value |
|---|---|---|
auth_type | false | string |
comment | false | string |
member_of | false | List of object references |
password | false | string |
storage | false | string |
user blocks
user.settings_profile
user.settings_profile attributes
| Name | Required | Value |
|---|---|---|
inherit | false | List of values, where each can be one of:
|
user.settings_profile blocks
user.settings_profile.setting
user.settings_profile.setting attributes
| Name | Required | Value |
|---|---|---|
max | false | Any value |
min | false | Any value |
value | true | Any value |
writability | false | Writability constraint can be one of:
|
user.settings_profile.setting constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Repeatable | true |
user constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., user "name" ) | true |
| Repeatable | true |
view
The view block describes a view in a database schema.
view "clean_users" {
schema = schema.public
column "id" {
type = int
}
...
}
view attributes
| Name | Required | Value |
|---|---|---|
as | true | string |
comment | false | string |
definer | false | User or role that defines the view can be one of:
|
depends_on | false | List of object references |
schema | true | Object reference to |
security | false |
|
view blocks
view.annotation
view.annotation constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown blocks | true |
| Allow unknown attributes | true |
view.column
view.column attributes
| Name | Required | Value |
|---|---|---|
comment | false | string |
null | false | bool |
type | true | Column type can be one of:
|
view.column blocks
view.column.annotation
view.column.annotation constraints
| Constraint | Value |
|---|---|
| Required | false |
| Require Name | false |
| Allow unknown blocks | true |
| Allow unknown attributes | true |
view.column constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., view.column "name" ) | true |
view constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., view "name" ) | true |
Allow Qualifier (e.g., view "schema" "name" ) | true |
| Mutually exclusive sets | [latest, git] |
wasm_module
The wasm_module block describes a ClickHouse WASM module (realm-level object).
wasm_module "my_module" {
code = sql("unhex('0061736d0100...')") // Expression producing the wasm binary.
hash = sql("reinterpretAsUInt256(unhex('369f...c57d'))") // Optional integrity hash expression.
}
The module code is write-only: inspection emits only the hash attribute
(absent while the module is not yet loaded). code is required in desired states.
wasm_module attributes
| Name | Required | Value |
|---|---|---|
code | true | Raw expression defined with |
hash | false | Raw expression defined with |
wasm_module constraints
| Constraint | Value |
|---|---|
| Required | false |
Require Name (e.g., wasm_module "name" ) | true |