Skip to main content

ClickHouse Schema

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
}
...
}

Attributes

NameRequiredValue
commentfalsestring
layouttrue

Raw expression defined with sql("expr")

schematrue

Object reference to schema

settingsfalsemap
sourcetrue

Raw expression defined with sql("expr")

Blocks

dictionary.attribute

dictionary.attribute attributes
NameRequiredValue
defaultfalse

Column default expression can be one of:

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

Attribute type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
dictionary.attribute constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

dictionary.key

dictionary.key attributes
NameRequiredValue
defaultfalse

Column default expression can be one of:

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

Attribute type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
dictionary.key constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

dictionary.lifetime

dictionary.lifetime attributes
NameRequiredValue
maxtrueint
mintrueint
dictionary.lifetime constraints
ConstraintValue
Requiredtrue
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

Constraints

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

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

enginefalse

Table engine can be one of:

  1. enum (MergeTree, SharedMergeTree, Memory)
  2. Raw expression defined with sql("expr")
populatefalsebool
schematrue

Object reference to schema

tofalse

Define structure of view can be one of:

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

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")
materialized.column constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

materialized.primary_key

materialized.primary_key attributes
NameRequiredValue
columnsfalse

Primary key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
materialized.primary_key blocks

materialized.primary_key.on

materialized.primary_key.on attributes
NameRequiredValue
columnfalse

Primary key column can be one of:

  1. Object reference to column
  2. Object reference to table.column
exprfalsestring
materialized.primary_key.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[column, expr]
One of required sets[column, expr]
materialized.primary_key constraints
ConstraintValue
Requiredfalse
Require Namefalse
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
Mutually exclusive sets[to, engine], [to, populate]
One of required sets[to, engine]

schema

The schema block describes a database schema.

schema "public" {
...
}

Attributes

NameRequiredValue
commentfalsestring
enginefalse

Schema engine can be one of:

  1. enum (Atomic, Lazy)
  2. Raw expression defined with sql("expr")
namefalsestring

Constraints

ConstraintValue
Requiredfalse
Require Nametrue
Allow Qualifierfalse
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
enginetrue

Table engine can be one of:

  1. enum (MergeTree, SharedMergeTree, Memory)
  2. Raw expression defined with sql("expr")
schematrue

Object reference to schema

settingsfalsemap
ttlfalse

Column ttl can be one of:

  1. string
  2. Raw expression defined with sql("expr")

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
codecfalse

Column codec can be one of:

  1. string
  2. Raw expression defined with sql("expr")
  3. enum (NONE, ZSTD, LZ4, LZ4HC, DoubleDelta, Gorilla, FPC, T64, AES_128_GCM_SIV, AES_256_GCM_SIV)
commentfalsestring
defaultfalse

Column default expression can be one of:

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

Column default kind can be one of:

  1. enum (DEFAULT, MATERIALIZED, EPHEMERAL, ALIAS)
nullfalsebool
ttlfalse

Column ttl can be one of:

  1. string
  2. Raw expression defined with sql("expr")
typetrue

Column type can be one of:

  1. Schema type
  2. Raw expression defined with sql("expr")
table.column constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse

table.index

table.index attributes
NameRequiredValue
commentfalsestring
granularityfalseint
typetrue

Index type can be one of:

  1. Raw expression defined with sql("expr")
  2. string
  3. enum (minmax, bloom_filter)
table.index blocks

table.index.on

table.index.on attributes
NameRequiredValue
exprtruestring
table.index.on constraints
ConstraintValue
Requiredtrue
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
table.index constraints
ConstraintValue
Requiredfalse
Require Nametrue
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse

table.primary_key

table.primary_key attributes
NameRequiredValue
columnsfalse

Primary key columns can be one of:

  1. List of object reference to column
  2. List of object reference to table.column
commentfalsestring
table.primary_key blocks

table.primary_key.on

table.primary_key.on attributes
NameRequiredValue
columnfalse

Primary key column can be one of:

  1. Object reference to column
  2. Object reference to table.column
exprfalsestring
table.primary_key.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[column, expr]
One of required sets[column, expr]
table.primary_key constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatablefalse
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[columns, on]
One of required sets[columns, on]

table.sort

table.sort attributes
NameRequiredValue
columnsfalse

List of object reference to column

table.sort blocks

table.sort.on

table.sort.on attributes
NameRequiredValue
columnfalse

Object reference to column

exprfalsestring
table.sort.on constraints
ConstraintValue
Requiredfalse
Require Namefalse
Repeatabletrue
Allow unknown blocksfalse
Allow unknown attributesfalse
Mutually exclusive sets[column, expr]
One of required sets[column, expr]
table.sort constraints
ConstraintValue
Requiredfalse
Require Namefalse
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

view

The view block describes a view in a database schema.

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

Attributes

NameRequiredValue
astruestring
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")
view.column 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
Mutually exclusive sets[latest, git]