SHOW Statements

SHOW CREATE TABLE

  1. SHOW CREATE [TEMPORARY] [TABLE|DICTIONARY] [db.]table [INTO OUTFILE filename] [FORMAT format]

Returns a single String-type ‘statement’ column, which contains a single value – the CREATE query used for creating the specified object.

SHOW DATABASES

Prints a list of all databases.

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

This statement is identical to the query:

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

Examples

Getting database names, containing the symbols sequence ‘de’ in their names:

  1. SHOW DATABASES LIKE '%de%'

Result:

  1. ┌─name────┐
  2. default
  3. └─────────┘

Getting database names, containing symbols sequence ‘de’ in their names, in the case insensitive manner:

  1. SHOW DATABASES ILIKE '%DE%'

Result:

  1. ┌─name────┐
  2. default
  3. └─────────┘

Getting database names, not containing the symbols sequence ‘de’ in their names:

  1. SHOW DATABASES NOT LIKE '%de%'

Result:

  1. ┌─name───────────────────────────┐
  2. _temporary_and_external_tables
  3. system
  4. test
  5. tutorial
  6. └────────────────────────────────┘

Getting the first two rows from database names:

  1. SHOW DATABASES LIMIT 2

Result:

  1. ┌─name───────────────────────────┐
  2. _temporary_and_external_tables
  3. default
  4. └────────────────────────────────┘

See Also

SHOW PROCESSLIST

  1. SHOW PROCESSLIST [INTO OUTFILE filename] [FORMAT format]

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

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

Tip (execute in the console):

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

SHOW TABLES

Displays a list of tables.

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

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

This statement is identical to the query:

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

Examples

Getting table names, containing the symbols sequence ‘user’ in their names:

  1. SHOW TABLES FROM system LIKE '%user%'

Result:

  1. ┌─name─────────────┐
  2. user_directories
  3. users
  4. └──────────────────┘

Getting table names, containing sequence ‘user’ in their names, in the case insensitive manner:

  1. SHOW TABLES FROM system ILIKE '%USER%'

Result:

  1. ┌─name─────────────┐
  2. user_directories
  3. users
  4. └──────────────────┘

Getting table names, not containing the symbol sequence ‘s’ in their names:

  1. SHOW TABLES FROM system NOT LIKE '%s%'

Result:

  1. ┌─name─────────┐
  2. metric_log
  3. metric_log_0
  4. metric_log_1
  5. └──────────────┘

Getting the first two rows from table names:

  1. SHOW TABLES FROM system LIMIT 2

Result:

  1. ┌─name───────────────────────────┐
  2. aggregate_function_combinators
  3. asynchronous_metric_log
  4. └────────────────────────────────┘

See Also

SHOW DICTIONARIES

Displays a list of external dictionaries.

  1. 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:

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

Example

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

  1. SHOW DICTIONARIES FROM db LIKE '%reg%' LIMIT 2
  1. ┌─name─────────┐
  2. regions
  3. region_names
  4. └──────────────┘

SHOW GRANTS

Shows privileges for a user.

Syntax

  1. SHOW GRANTS [FOR user1 [, user2 ...]]

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

SHOW CREATE USER

Shows parameters that were used at a user creation.

SHOW CREATE USER doesn’t output user passwords.

Syntax

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

SHOW CREATE ROLE

Shows parameters that were used at a role creation.

Syntax

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

SHOW CREATE ROW POLICY

Shows parameters that were used at a row policy creation.

Syntax

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

SHOW CREATE QUOTA

Shows parameters that were used at a quota creation.

Syntax

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

SHOW CREATE SETTINGS PROFILE

Shows parameters that were used at a settings profile creation.

Syntax

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

SHOW USERS

Returns a list of user account names. To view user accounts parameters, see the system table system.users.

Syntax

  1. SHOW USERS

SHOW ROLES

Returns a list of roles. To view another parameters, see system tables system.roles and system.role-grants.

Syntax

  1. SHOW [CURRENT|ENABLED] ROLES

SHOW PROFILES

Returns a list of setting profiles. To view user accounts parameters, see the system table settings_profiles.

Syntax

  1. SHOW [SETTINGS] PROFILES

SHOW POLICIES

Returns a list of row policies for the specified table. To view user accounts parameters, see the system table system.row_policies.

Syntax

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

SHOW QUOTAS

Returns a list of quotas. To view quotas parameters, see the system table system.quotas.

Syntax

  1. SHOW QUOTAS

SHOW QUOTA

Returns a quota consumption for all users or for current user. To view another parameters, see system tables system.quotas_usage and system.quota_usage.

Syntax

  1. SHOW [CURRENT] QUOTA

SHOW ACCESS

Shows all users, roles, profiles, etc. and all their grants.

Syntax

  1. SHOW ACCESS

SHOW CLUSTER(s)

Returns a list of clusters. All available clusters are listed in the system.clusters table.

Note

SHOW CLUSTER name query displays the contents of system.clusters table for this cluster.

Syntax

  1. SHOW CLUSTER '<name>'
  2. SWOW CLUSTERS [LIKE|NOT LIKE '<pattern>'] [LIMIT <N>]

Examples

Query:

  1. SHOW CLUSTERS;

Result:

  1. ┌─cluster──────────────────────────────────────┐
  2. test_cluster_two_shards
  3. test_cluster_two_shards_internal_replication
  4. test_cluster_two_shards_localhost
  5. test_shard_localhost
  6. test_shard_localhost_secure
  7. test_unavailable_shard
  8. └──────────────────────────────────────────────┘

Query:

  1. SHOW CLUSTERS LIKE 'test%' LIMIT 1;

Result:

  1. ┌─cluster─────────────────┐
  2. test_cluster_two_shards
  3. └─────────────────────────┘

Query:

  1. SHOW CLUSTER 'test_shard_localhost' FORMAT Vertical;

Result:

  1. Row 1:
  2. ──────
  3. cluster: test_shard_localhost
  4. shard_num: 1
  5. shard_weight: 1
  6. replica_num: 1
  7. host_name: localhost
  8. host_address: 127.0.0.1
  9. port: 9000
  10. is_local: 1
  11. user: default
  12. default_database:
  13. errors_count: 0
  14. estimated_recovery_time: 0

Original article