Back to Clickhouse

SHOW Statements

docs/en/sql-reference/statements/show.md

26.4.1.1-new29.3 KB
Original Source

:::note

SHOW CREATE (TABLE|DATABASE|USER) hides secrets unless the following settings are turned on:

Additionally, the user should have the displaySecretsInShowAndSelect privilege. :::

SHOW CREATE TABLE | DICTIONARY | VIEW | DATABASE {#show-create-table--dictionary--view--database}

These statements return a single column of type String, containing the CREATE query used for creating the specified object.

Syntax {#syntax}

sql
SHOW [CREATE] TABLE | TEMPORARY TABLE | DICTIONARY | VIEW | DATABASE [db.]table|view [INTO OUTFILE filename] [FORMAT format]

:::note If you use this statement to get the CREATE query of system tables, you will get a fake query, which only declares the table structure, but cannot be used to create a table. :::

SHOW DATABASES {#show-databases}

This statement prints a list of all databases.

Syntax {#syntax-1}

sql
SHOW DATABASES [[NOT] LIKE | ILIKE '<pattern>'] [LIMIT <N>] [INTO OUTFILE filename] [FORMAT format]

It is identical to the query:

sql
SELECT name FROM system.databases [WHERE name [NOT] LIKE | ILIKE '<pattern>'] [LIMIT <N>] [INTO OUTFILE filename] [FORMAT format]

Examples {#examples}

In this example we use SHOW to obtain database names containing the symbol sequence 'de' in their names:

sql
SHOW DATABASES LIKE '%de%'
text
┌─name────┐
│ default │
└─────────┘

We can also do so in a case-insensitive manner:

sql
SHOW DATABASES ILIKE '%DE%'
text
┌─name────┐
│ default │
└─────────┘

Or get database names which do not contain 'de' in their names:

sql
SHOW DATABASES NOT LIKE '%de%'
text
┌─name───────────────────────────┐
│ _temporary_and_external_tables │
│ system                         │
│ test                           │
│ tutorial                       │
└────────────────────────────────┘

Finally, we can get the names of only the first two databases:

sql
SHOW DATABASES LIMIT 2
text
┌─name───────────────────────────┐
│ _temporary_and_external_tables │
│ default                        │
└────────────────────────────────┘

See also {#see-also}

SHOW TABLES {#show-tables}

The SHOW TABLES statement displays a list of tables.

Syntax {#syntax-2}

sql
SHOW [FULL] [TEMPORARY] TABLES [{FROM | IN} <db>] [[NOT] LIKE | ILIKE '<pattern>'] [LIMIT <N>] [INTO OUTFILE <filename>] [FORMAT <format>]

If the FROM clause is not specified, the query returns a list of tables from the current database.

This statement is identical to the query:

sql
SELECT name FROM system.tables [WHERE name [NOT] LIKE | ILIKE '<pattern>'] [LIMIT <N>] [INTO OUTFILE <filename>] [FORMAT <format>]

Examples {#examples-1}

In this example we use the SHOW TABLES statement to find all tables containing 'user' in their names:

sql
SHOW TABLES FROM system LIKE '%user%'
text
┌─name─────────────┐
│ user_directories │
│ users            │
└──────────────────┘

We can also do so in a case-insensitive manner:

sql
SHOW TABLES FROM system ILIKE '%USER%'
text
┌─name─────────────┐
│ user_directories │
│ users            │
└──────────────────┘

Or to find tables which don't contain the letter 's' in their names:

sql
SHOW TABLES FROM system NOT LIKE '%s%'
text
┌─name─────────┐
│ metric_log   │
│ metric_log_0 │
│ metric_log_1 │
└──────────────┘

Finally, we can get the names of only the first two tables:

sql
SHOW TABLES FROM system LIMIT 2
text
┌─name───────────────────────────┐
│ aggregate_function_combinators │
│ asynchronous_metric_log        │
└────────────────────────────────┘

See also {#see-also-1}

SHOW COLUMNS {#show_columns}

The SHOW COLUMNS statement displays a list of columns.

Syntax {#syntax-3}

sql
SHOW [EXTENDED] [FULL] COLUMNS {FROM | IN} <table> [{FROM | IN} <db>] [{[NOT] {LIKE | ILIKE} '<pattern>' | WHERE <expr>}] [LIMIT <N>] [INTO
OUTFILE <filename>] [FORMAT <format>]

The database and table name can be specified in abbreviated form as <db>.<table>, meaning that FROM tab FROM db and FROM db.tab are equivalent. If no database is specified, the query returns the list of columns from the current database.

There are also two optional keywords: EXTENDED and FULL. The EXTENDED keyword currently has no effect, and exists for MySQL compatibility. The FULL keyword causes the output to include the collation, comment and privilege columns.

The SHOW COLUMNS statement produces a result table with the following structure:

ColumnDescriptionType
fieldThe name of the columnString
typeThe column data type. If the query was made through the MySQL wire protocol, then the equivalent type name in MySQL is shown.String
nullYES if the column data type is Nullable, NO otherwiseString
keyPRI if the column is part of the primary key, SOR if the column is part of the sorting key, empty otherwiseString
defaultDefault expression of the column if it is of type ALIAS, DEFAULT, or MATERIALIZED, otherwise NULL.Nullable(String)
extraAdditional information, currently unusedString
collation(only if FULL keyword was specified) Collation of the column, always NULL because ClickHouse has no per-column collationsNullable(String)
comment(only if FULL keyword was specified) Comment on the columnString
privilege(only if FULL keyword was specified) The privilege you have on this column, currently not availableString

Examples {#examples-2}

In this example we'll use the SHOW COLUMNS statement to get information about all columns in table 'orders', starting from 'delivery_':

sql
SHOW COLUMNS FROM 'orders' LIKE 'delivery_%'
text
┌─field───────────┬─type─────┬─null─┬─key─────┬─default─┬─extra─┐
│ delivery_date   │ DateTime │    0 │ PRI SOR │ ᴺᵁᴸᴸ    │       │
│ delivery_status │ Bool     │    0 │         │ ᴺᵁᴸᴸ    │       │
└─────────────────┴──────────┴──────┴─────────┴─────────┴───────┘

See also {#see-also-2}

SHOW DICTIONARIES {#show-dictionaries}

The SHOW DICTIONARIES statement displays a list of Dictionaries.

Syntax {#syntax-4}

sql
SHOW DICTIONARIES [FROM <db>] [LIKE '<pattern>'] [LIMIT <N>] [INTO OUTFILE <filename>] [FORMAT <format>]

If the FROM clause is not specified, the query returns the list of dictionaries from the current database.

You can get the same results as the SHOW DICTIONARIES query in the following way:

sql
SELECT name FROM system.dictionaries WHERE database = <db> [AND name LIKE <pattern>] [LIMIT <N>] [INTO OUTFILE <filename>] [FORMAT <format>]

Examples {#examples-3}

The following query selects the first two rows from the list of tables in the system database, whose names contain reg.

sql
SHOW DICTIONARIES FROM db LIKE '%reg%' LIMIT 2
text
┌─name─────────┐
│ regions      │
│ region_names │
└──────────────┘

SHOW INDEX {#show-index}

Displays a list of primary and data skipping indexes of a table.

This statement mostly exists for compatibility with MySQL. System tables system.tables (for primary keys) and system.data_skipping_indices (for data skipping indices) provide equivalent information but in a fashion more native to ClickHouse.

Syntax {#syntax-5}

sql
SHOW [EXTENDED] {INDEX | INDEXES | INDICES | KEYS } {FROM | IN} <table> [{FROM | IN} <db>] [WHERE <expr>] [INTO OUTFILE <filename>] [FORMAT <format>]

The database and table name can be specified in abbreviated form as <db>.<table>, i.e. FROM tab FROM db and FROM db.tab are equivalent. If no database is specified, the query assumes the current database as database.

The optional keyword EXTENDED currently has no effect, and exists for MySQL compatibility.

The statement produces a result table with the following structure:

ColumnDescriptionType
tableThe name of the table.String
non_uniqueAlways 1 as ClickHouse does not support uniqueness constraints.UInt8
key_nameThe name of the index, PRIMARY if the index is a primary key index.String
seq_in_indexFor a primary key index, the position of the column starting from 1. For a data skipping index: always 1.UInt8
column_nameFor a primary key index, the name of the column. For a data skipping index: '' (empty string), see field "expression".String
collationThe sorting of the column in the index: A if ascending, D if descending, NULL if unsorted.Nullable(String)
cardinalityAn estimation of the index cardinality (number of unique values in the index). Currently always 0.UInt64
sub_partAlways NULL because ClickHouse does not support index prefixes like MySQL.Nullable(String)
packedAlways NULL because ClickHouse does not support packed indexes (like MySQL).Nullable(String)
nullCurrently unused
index_typeThe index type, e.g. PRIMARY, MINMAX, BLOOM_FILTER etc.String
commentAdditional information about the index, currently always '' (empty string).String
index_comment'' (empty string) because indexes in ClickHouse cannot have a COMMENT field (like in MySQL).String
visibleIf the index is visible to the optimizer, always YES.String
expressionFor a data skipping index, the index expression. For a primary key index: '' (empty string).String

Examples {#examples-4}

In this example we use the SHOW INDEX statement to get information about all indexes in table 'tbl'

sql
SHOW INDEX FROM 'tbl'
text
┌─table─┬─non_unique─┬─key_name─┬─seq_in_index─┬─column_name─┬─collation─┬─cardinality─┬─sub_part─┬─packed─┬─null─┬─index_type───┬─comment─┬─index_comment─┬─visible─┬─expression─┐
│ tbl   │          1 │ blf_idx  │ 1            │ 1           │ ᴺᵁᴸᴸ      │ 0           │ ᴺᵁᴸᴸ     │ ᴺᵁᴸᴸ   │ ᴺᵁᴸᴸ │ BLOOM_FILTER │         │               │ YES     │ d, b       │
│ tbl   │          1 │ mm1_idx  │ 1            │ 1           │ ᴺᵁᴸᴸ      │ 0           │ ᴺᵁᴸᴸ     │ ᴺᵁᴸᴸ   │ ᴺᵁᴸᴸ │ MINMAX       │         │               │ YES     │ a, c, d    │
│ tbl   │          1 │ mm2_idx  │ 1            │ 1           │ ᴺᵁᴸᴸ      │ 0           │ ᴺᵁᴸᴸ     │ ᴺᵁᴸᴸ   │ ᴺᵁᴸᴸ │ MINMAX       │         │               │ YES     │ c, d, e    │
│ tbl   │          1 │ PRIMARY  │ 1            │ c           │ A         │ 0           │ ᴺᵁᴸᴸ     │ ᴺᵁᴸᴸ   │ ᴺᵁᴸᴸ │ PRIMARY      │         │               │ YES     │            │
│ tbl   │          1 │ PRIMARY  │ 2            │ a           │ A         │ 0           │ ᴺᵁᴸᴸ     │ ᴺᵁᴸᴸ   │ ᴺᵁᴸᴸ │ PRIMARY      │         │               │ YES     │            │
│ tbl   │          1 │ set_idx  │ 1            │ 1           │ ᴺᵁᴸᴸ      │ 0           │ ᴺᵁᴸᴸ     │ ᴺᵁᴸᴸ   │ ᴺᵁᴸᴸ │ SET          │         │               │ YES     │ e          │
└───────┴────────────┴──────────┴──────────────┴─────────────┴───────────┴─────────────┴──────────┴────────┴──────┴──────────────┴─────────┴───────────────┴─────────┴────────────┘

See also {#see-also-3}

SHOW PROCESSLIST {#show-processlist}

Outputs the content of the system.processes table, that contains a list of queries that are being processed at the moment, excluding SHOW PROCESSLIST queries.

Syntax {#syntax-6}

sql
SHOW PROCESSLIST [INTO OUTFILE filename] [FORMAT format]

The SELECT * FROM system.processes query returns data about all the current queries.

:::tip Execute in the console:

bash
$ watch -n1 "clickhouse-client --query='SHOW PROCESSLIST'"

:::

SHOW GRANTS {#show-grants}

The SHOW GRANTS statement shows privileges for a user.

Syntax {#syntax-7}

sql
SHOW GRANTS [FOR user1 [, user2 ...]] [WITH IMPLICIT] [FINAL]

If the user is not specified, the query returns privileges for the current user.

The WITH IMPLICIT modifier allows showing the implicit grants (e.g., GRANT SELECT ON system.one)

The FINAL modifier merges all grants from the user and its granted roles (with inheritance)

SHOW CREATE USER {#show-create-user}

The SHOW CREATE USER statement shows parameters which were used at user creation.

Syntax {#syntax-8}

sql
SHOW CREATE USER [name1 [, name2 ...] | CURRENT_USER]

SHOW CREATE ROLE {#show-create-role}

The SHOW CREATE ROLE statement shows parameters which were used at role creation.

Syntax {#syntax-9}

sql
SHOW CREATE ROLE name1 [, name2 ...]

SHOW CREATE ROW POLICY {#show-create-row-policy}

The SHOW CREATE ROW POLICY statement shows parameters which were used at row policy creation.

Syntax {#syntax-10}

sql
SHOW CREATE [ROW] POLICY name ON [database1.]table1 [, [database2.]table2 ...]

SHOW CREATE QUOTA {#show-create-quota}

The SHOW CREATE QUOTA statement shows parameters which were used at quota creation.

Syntax {#syntax-11}

sql
SHOW CREATE QUOTA [name1 [, name2 ...] | CURRENT]

SHOW CREATE SETTINGS PROFILE {#show-create-settings-profile}

The SHOW CREATE SETTINGS PROFILE statement shows parameters which were used at settings profile creation.

Syntax {#syntax-12}

sql
SHOW CREATE [SETTINGS] PROFILE name1 [, name2 ...]

SHOW USERS {#show-users}

The SHOW USERS statement returns a list of user account names. To view user accounts parameters, see the system table system.users.

Syntax {#syntax-13}

sql
SHOW USERS

SHOW ROLES {#show-roles}

The SHOW ROLES statement returns a list of roles. To view other parameters, see system tables system.roles and system.role_grants.

Syntax {#syntax-14}

sql
SHOW [CURRENT|ENABLED] ROLES

SHOW PROFILES {#show-profiles}

The SHOW PROFILES statement returns a list of setting profiles. To view user accounts parameters, see system table settings_profiles.

Syntax {#syntax-15}

sql
SHOW [SETTINGS] PROFILES

SHOW POLICIES {#show-policies}

The SHOW POLICIES statement returns a list of row policies for the specified table. To view user accounts parameters, see system table system.row_policies.

Syntax {#syntax-16}

sql
SHOW [ROW] POLICIES [ON [db.]table]

SHOW QUOTAS {#show-quotas}

The SHOW QUOTAS statement returns a list of quotas. To view quotas parameters, see the system table system.quotas.

Syntax {#syntax-17}

sql
SHOW QUOTAS

SHOW QUOTA {#show-quota}

The SHOW QUOTA statement returns a quota consumption for all users or for current user. To view other parameters, see system tables system.quotas_usage and system.quota_usage.

Syntax {#syntax-18}

sql
SHOW [CURRENT] QUOTA

SHOW ACCESS {#show-access}

The SHOW ACCESS statement shows all users, roles, profiles, etc. and all their grants.

Syntax {#syntax-19}

sql
SHOW ACCESS

SHOW CLUSTER(S) {#show-clusters}

The SHOW CLUSTER(S) statement returns a list of clusters. All available clusters are listed in the system.clusters table.

:::note The SHOW CLUSTER name query displays cluster, shard_num, replica_num, host_name, host_address, and port of the system.clusters table for the specified cluster name. :::

Syntax {#syntax-20}

sql
SHOW CLUSTER '<name>'
SHOW CLUSTERS [[NOT] LIKE|ILIKE '<pattern>'] [LIMIT <N>]

Examples {#examples-5}

sql
SHOW CLUSTERS;
text
┌─cluster──────────────────────────────────────┐
│ test_cluster_two_shards                      │
│ test_cluster_two_shards_internal_replication │
│ test_cluster_two_shards_localhost            │
│ test_shard_localhost                         │
│ test_shard_localhost_secure                  │
│ test_unavailable_shard                       │
└──────────────────────────────────────────────┘
sql
SHOW CLUSTERS LIKE 'test%' LIMIT 1;
text
┌─cluster─────────────────┐
│ test_cluster_two_shards │
└─────────────────────────┘
sql
SHOW CLUSTER 'test_shard_localhost' FORMAT Vertical;
text
Row 1:
──────
cluster:                 test_shard_localhost
shard_num:               1
replica_num:             1
host_name:               localhost
host_address:            127.0.0.1
port:                    9000

SHOW SETTINGS {#show-settings}

The SHOW SETTINGS statement returns a list of system settings and their values. It selects data from the system.settings table.

Syntax {#syntax-21}

sql
SHOW [CHANGED] SETTINGS LIKE|ILIKE <name>

Clauses {#clauses}

LIKE|ILIKE allow to specify a matching pattern for the setting name. It can contain globs such as % or _. LIKE clause is case-sensitive, ILIKE — case insensitive.

When the CHANGED clause is used, the query returns only settings changed from their default values.

Examples {#examples-6}

Query with the LIKE clause:

sql
SHOW SETTINGS LIKE 'send_timeout';
text
┌─name─────────┬─type────┬─value─┐
│ send_timeout │ Seconds │ 300   │
└──────────────┴─────────┴───────┘

Query with the ILIKE clause:

sql
SHOW SETTINGS ILIKE '%CONNECT_timeout%'
text
┌─name────────────────────────────────────┬─type─────────┬─value─┐
│ connect_timeout                         │ Seconds      │ 10    │
│ connect_timeout_with_failover_ms        │ Milliseconds │ 50    │
│ connect_timeout_with_failover_secure_ms │ Milliseconds │ 100   │
└─────────────────────────────────────────┴──────────────┴───────┘

Query with the CHANGED clause:

sql
SHOW CHANGED SETTINGS ILIKE '%MEMORY%'
text
┌─name─────────────┬─type───┬─value───────┐
│ max_memory_usage │ UInt64 │ 10000000000 │
└──────────────────┴────────┴─────────────┘

SHOW SETTING {#show-setting}

The SHOW SETTING statement outputs setting value for specified setting name.

Syntax {#syntax-22}

sql
SHOW SETTING <name>

See also {#see-also-4}

SHOW FILESYSTEM CACHES {#show-filesystem-caches}

Examples {#examples-7}

sql
SHOW FILESYSTEM CACHES
text
┌─Caches────┐
│ s3_cache  │
└───────────┘

See also {#see-also-5}

SHOW ENGINES {#show-engines}

The SHOW ENGINES statement outputs the content of the system.table_engines table, that contains description of table engines supported by server and their feature support information.

Syntax {#syntax-23}

sql
SHOW ENGINES [INTO OUTFILE filename] [FORMAT format]

See also {#see-also-6}

SHOW FUNCTIONS {#show-functions}

The SHOW FUNCTIONS statement outputs the content of the system.functions table.

Syntax {#syntax-24}

sql
SHOW FUNCTIONS [LIKE | ILIKE '<pattern>']

If either LIKE or ILIKE clause is specified, the query returns a list of system functions whose names match the provided <pattern>.

See Also {#see-also-7}

SHOW MERGES {#show-merges}

The SHOW MERGES statement returns a list of merges. All merges are listed in the system.merges table:

ColumnDescription
tableTable name.
databaseThe name of the database the table is in.
estimate_completeThe estimated time to complete (in seconds).
elapsedThe time elapsed (in seconds) since the merge started.
progressThe percentage of completed work (0-100 percent).
is_mutation1 if this process is a part mutation.
size_compressedThe total size of the compressed data of the merged parts.
memory_usageMemory consumption of the merge process.

Syntax {#syntax-25}

sql
SHOW MERGES [[NOT] LIKE|ILIKE '<table_name_pattern>'] [LIMIT <N>]

Examples {#examples-8}

sql
SHOW MERGES;
text
┌─table──────┬─database─┬─estimate_complete─┬─elapsed─┬─progress─┬─is_mutation─┬─size_compressed─┬─memory_usage─┐
│ your_table │ default  │              0.14 │    0.36 │    73.01 │           0 │        5.40 MiB │    10.25 MiB │
└────────────┴──────────┴───────────────────┴─────────┴──────────┴─────────────┴─────────────────┴──────────────┘
sql
SHOW MERGES LIKE 'your_t%' LIMIT 1;
text
┌─table──────┬─database─┬─estimate_complete─┬─elapsed─┬─progress─┬─is_mutation─┬─size_compressed─┬─memory_usage─┐
│ your_table │ default  │              0.14 │    0.36 │    73.01 │           0 │        5.40 MiB │    10.25 MiB │
└────────────┴──────────┴───────────────────┴─────────┴──────────┴─────────────┴─────────────────┴──────────────┘

SHOW CREATE MASKING POLICY {#show-create-masking-policy}

The SHOW CREATE MASKING POLICY statement shows parameters which were used at masking policy creation.

Syntax {#syntax-26}

sql
SHOW CREATE MASKING POLICY name ON [database.]table