Merge pull request #54773 from slvrtrn/tableau-online-information-schema

Adjust information_schema to support Tableau Online via MySQL interface
This commit is contained in:
Robert Schulze 2023-09-22 16:11:55 +02:00 committed by GitHub
commit 2ca0e2e07d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 585 additions and 227 deletions

View File

@ -13,16 +13,20 @@ SHOW TABLES FROM information_schema;
```
``` text
┌─name─────┐
│ COLUMNS │
│ SCHEMATA │
│ TABLES │
│ VIEWS │
│ columns │
│ schemata │
│ tables │
│ views │
└──────────┘
┌─name────────────────────┐
│ COLUMNS │
│ KEY_COLUMN_USAGE │
│ REFERENTIAL_CONSTRAINTS │
│ SCHEMATA │
│ TABLES │
│ VIEWS │
│ columns │
│ key_column_usage │
│ referential_constraints │
│ schemata │
│ tables │
│ views │
└─────────────────────────┘
```
`INFORMATION_SCHEMA` contains the following views:
@ -31,8 +35,10 @@ SHOW TABLES FROM information_schema;
- [SCHEMATA](#schemata)
- [TABLES](#tables)
- [VIEWS](#views)
- [KEY_COLUMN_USAGE](#key_column_usage)
- [REFERENTIAL_CONSTRAINTS](#referential_constraints)
Case-insensitive equivalent views, e.g. `INFORMATION_SCHEMA.columns` are provided for reasons of compatibility with other databases.
Case-insensitive equivalent views, e.g. `INFORMATION_SCHEMA.columns` are provided for reasons of compatibility with other databases. The same applies to all the columns in these views - both lowercase (for example, `table_name`) and uppercase (`TABLE_NAME`) variants are provided.
## COLUMNS {#columns}
@ -69,7 +75,36 @@ Columns:
Query:
``` sql
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE (table_schema=currentDatabase() OR table_schema='') AND table_name NOT LIKE '%inner%' LIMIT 1 FORMAT Vertical;
SELECT table_catalog,
table_schema,
table_name,
column_name,
ordinal_position,
column_default,
is_nullable,
data_type,
character_maximum_length,
character_octet_length,
numeric_precision,
numeric_precision_radix,
numeric_scale,
datetime_precision,
character_set_catalog,
character_set_schema,
character_set_name,
collation_catalog,
collation_schema,
collation_name,
domain_catalog,
domain_schema,
domain_name,
column_comment,
column_type
FROM INFORMATION_SCHEMA.COLUMNS
WHERE (table_schema = currentDatabase() OR table_schema = '')
AND table_name NOT LIKE '%inner%'
LIMIT 1
FORMAT Vertical;
```
Result:
@ -121,7 +156,17 @@ Columns:
Query:
``` sql
SELECT * FROM information_schema.schemata WHERE schema_name ILIKE 'information_schema' LIMIT 1 FORMAT Vertical;
SELECT catalog_name,
schema_name,
schema_owner,
default_character_set_catalog,
default_character_set_schema,
default_character_set_name,
sql_path
FROM information_schema.schemata
WHERE schema_name ilike 'information_schema'
LIMIT 1
FORMAT Vertical;
```
Result:
@ -147,19 +192,31 @@ Columns:
- `table_catalog` ([String](../../sql-reference/data-types/string.md)) — The name of the database in which the table is located.
- `table_schema` ([String](../../sql-reference/data-types/string.md)) — The name of the database in which the table is located.
- `table_name` ([String](../../sql-reference/data-types/string.md)) — Table name.
- `table_type` ([Enum8](../../sql-reference/data-types/enum.md)) — Table type. Possible values:
- `table_type` ([String](../../sql-reference/data-types/string.md)) — Table type. Possible values:
- `BASE TABLE`
- `VIEW`
- `FOREIGN TABLE`
- `LOCAL TEMPORARY`
- `SYSTEM VIEW`
- `table_comment` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — The comment used when creating the table.
- `table_collation` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — The table default collation. Always `utf8mb4`.
**Example**
Query:
``` sql
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE (table_schema = currentDatabase() OR table_schema = '') AND table_name NOT LIKE '%inner%' LIMIT 1 FORMAT Vertical;
SELECT table_catalog,
table_schema,
table_name,
table_type,
table_collation,
table_comment
FROM INFORMATION_SCHEMA.TABLES
WHERE (table_schema = currentDatabase() OR table_schema = '')
AND table_name NOT LIKE '%inner%'
LIMIT 1
FORMAT Vertical;
```
Result:
@ -167,10 +224,12 @@ Result:
``` text
Row 1:
──────
table_catalog: default
table_schema: default
table_name: describe_example
table_type: BASE TABLE
table_catalog: default
table_schema: default
table_name: describe_example
table_type: BASE TABLE
table_collation: utf8mb4_0900_ai_ci
table_comment:
```
## VIEWS {#views}
@ -199,7 +258,20 @@ Query:
``` sql
CREATE VIEW v (n Nullable(Int32), f Float64) AS SELECT n, f FROM t;
CREATE MATERIALIZED VIEW mv ENGINE = Null AS SELECT * FROM system.one;
SELECT * FROM information_schema.views WHERE table_schema = currentDatabase() LIMIT 1 FORMAT Vertical;
SELECT table_catalog,
table_schema,
table_name,
view_definition,
check_option,
is_updatable,
is_insertable_into,
is_trigger_updatable,
is_trigger_deletable,
is_trigger_insertable_into
FROM information_schema.views
WHERE table_schema = currentDatabase()
LIMIT 1
FORMAT Vertical;
```
Result:
@ -218,3 +290,80 @@ is_trigger_updatable: NO
is_trigger_deletable: NO
is_trigger_insertable_into: NO
```
## KEY_COLUMN_USAGE (#key_column_usage)
Contains columns from the [system.tables](../../operations/system-tables/tables.md) system table which are restricted by constraints.
Columns:
- `constraint_catalog` ([String](../../sql-reference/data-types/string.md)) — Currently unused. Always `def`.
- `constraint_schema` ([String](../../sql-reference/data-types/string.md)) — The name of the schema (database) to which the constraint belongs.
- `constraint_name` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — The name of the constraint.
- `table_catalog` ([String](../../sql-reference/data-types/string.md)) — Currently unused. Always `def`.
- `table_schema` ([String](../../sql-reference/data-types/string.md)) — The name of the schema (database) to which the table belongs.
- `table_name` ([String](../../sql-reference/data-types/string.md)) — The name of the table that has the constraint.
- `column_name` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — The name of the column that has the constraint.
- `ordinal_position` ([UInt32](../../sql-reference/data-types/int-uint.md)) — Currently unused. Always `1`.
- `position_in_unique_constraint` ([Nullable](../../sql-reference/data-types/nullable.md)([UInt32](../../sql-reference/data-types/int-uint.md))) — Currently unused. Always `NULL`.
- `referenced_table_schema` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — Currently unused. Always NULL.
- `referenced_table_name` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — Currently unused. Always NULL.
- `referenced_column_name` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — Currently unused. Always NULL.
**Example**
```sql
CREATE TABLE test (i UInt32, s String) ENGINE MergeTree ORDER BY i;
SELECT constraint_catalog,
constraint_schema,
constraint_name,
table_catalog,
table_schema,
table_name,
column_name,
ordinal_position,
position_in_unique_constraint,
referenced_table_schema,
referenced_table_name,
referenced_column_name
FROM information_schema.key_column_usage
WHERE table_name = 'test'
FORMAT Vertical;
```
Result:
```
Row 1:
──────
constraint_catalog: def
constraint_schema: default
constraint_name: PRIMARY
table_catalog: def
table_schema: default
table_name: test
column_name: i
ordinal_position: 1
position_in_unique_constraint: ᴺᵁᴸᴸ
referenced_table_schema: ᴺᵁᴸᴸ
referenced_table_name: ᴺᵁᴸᴸ
referenced_column_name: ᴺᵁᴸᴸ
```
## REFERENTIAL_CONSTRAINTS (#referential_constraints)
Contains information about foreign keys. Currently returns an empty result (no rows) which is just enough to provide compatibility with 3rd party tools like Tableau Online.
Columns:
- `constraint_catalog` ([String](../../sql-reference/data-types/string.md)) — Currently unused.
- `constraint_schema` ([String](../../sql-reference/data-types/string.md)) — Currently unused.
- `constraint_name` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — Currently unused.
- `unique_constraint_catalog` ([String](../../sql-reference/data-types/string.md)) — Currently unused.
- `unique_constraint_schema` ([String](../../sql-reference/data-types/string.md)) — Currently unused.
- `unique_constraint_name` ([Nullable](../../sql-reference/data-types/nullable.md)([String](../../sql-reference/data-types/string.md))) — Currently unused.
- `match_option` ([String](../../sql-reference/data-types/string.md)) — Currently unused.
- `update_rule` ([String](../../sql-reference/data-types/string.md)) — Currently unused.
- `delete_rule` ([String](../../sql-reference/data-types/string.md)) — Currently unused.
- `table_name` ([String](../../sql-reference/data-types/string.md)) — Currently unused.
- `referenced_table_name` ([String](../../sql-reference/data-types/string.md)) — Currently unused.

View File

@ -1,82 +0,0 @@
ATTACH VIEW columns
(
`table_catalog` String,
`table_schema` String,
`table_name` String,
`TABLE_SCHEMA` String,
`TABLE_NAME` String,
`column_name` String,
`ordinal_position` UInt64,
`column_default` String,
`is_nullable` String,
`data_type` String,
`character_maximum_length` Nullable(UInt64),
`character_octet_length` Nullable(UInt64),
`numeric_precision` Nullable(UInt64),
`numeric_precision_radix` Nullable(UInt64),
`numeric_scale` Nullable(UInt64),
`datetime_precision` Nullable(UInt64),
`character_set_catalog` Nullable(String),
`character_set_schema` Nullable(String),
`character_set_name` Nullable(String),
`collation_catalog` Nullable(String),
`collation_schema` Nullable(String),
`collation_name` Nullable(String),
`domain_catalog` Nullable(String),
`domain_schema` Nullable(String),
`domain_name` Nullable(String),
`column_comment` String,
`column_type` String,
`TABLE_CATALOG` String ALIAS table_catalog,
`COLUMN_NAME` String ALIAS column_name,
`ORDINAL_POSITION` UInt64 ALIAS ordinal_position,
`COLUMN_DEFAULT` String ALIAS column_default,
`IS_NULLABLE` String ALIAS is_nullable,
`DATA_TYPE` String ALIAS data_type,
`CHARACTER_MAXIMUM_LENGTH` Nullable(UInt64) ALIAS character_maximum_length,
`CHARACTER_OCTET_LENGTH` Nullable(UInt64) ALIAS character_octet_length,
`NUMERIC_PRECISION` Nullable(UInt64) ALIAS numeric_precision,
`NUMERIC_PRECISION_RADIX` Nullable(UInt64) ALIAS numeric_precision_radix,
`NUMERIC_SCALE` Nullable(UInt64) ALIAS numeric_scale,
`DATETIME_PRECISION` Nullable(UInt64) ALIAS datetime_precision,
`CHARACTER_SET_CATALOG` Nullable(String) ALIAS character_set_catalog,
`CHARACTER_SET_SCHEMA` Nullable(String) ALIAS character_set_schema,
`CHARACTER_SET_NAME` Nullable(String) ALIAS character_set_name,
`COLLATION_CATALOG` Nullable(String) ALIAS collation_catalog,
`COLLATION_SCHEMA` Nullable(String) ALIAS collation_schema,
`COLLATION_NAME` Nullable(String) ALIAS collation_name,
`DOMAIN_CATALOG` Nullable(String) ALIAS domain_catalog,
`DOMAIN_SCHEMA` Nullable(String) ALIAS domain_schema,
`DOMAIN_NAME` Nullable(String) ALIAS domain_name,
`COLUMN_COMMENT` String ALIAS column_comment,
`COLUMN_TYPE` String ALIAS column_type
) AS
SELECT
database AS table_catalog,
database AS table_schema,
database AS TABLE_SCHEMA,
table AS table_name,
table AS TABLE_NAME,
name AS column_name,
position AS ordinal_position,
default_expression AS column_default,
type LIKE 'Nullable(%)' AS is_nullable,
type AS data_type,
character_octet_length AS character_maximum_length,
character_octet_length,
numeric_precision,
numeric_precision_radix,
numeric_scale,
datetime_precision,
NULL AS character_set_catalog,
NULL AS character_set_schema,
NULL AS character_set_name,
NULL AS collation_catalog,
NULL AS collation_schema,
NULL AS collation_name,
NULL AS domain_catalog,
NULL AS domain_schema,
NULL AS domain_name,
comment AS column_comment,
type AS column_type
FROM system.columns

View File

@ -1,26 +0,0 @@
ATTACH VIEW schemata
(
`catalog_name` String,
`schema_name` String,
`schema_owner` String,
`default_character_set_catalog` Nullable(String),
`default_character_set_schema` Nullable(String),
`default_character_set_name` Nullable(String),
`sql_path` Nullable(String),
`CATALOG_NAME` String ALIAS catalog_name,
`SCHEMA_NAME` String ALIAS schema_name,
`SCHEMA_OWNER` String ALIAS schema_owner,
`DEFAULT_CHARACTER_SET_CATALOG` Nullable(String) ALIAS default_character_set_catalog,
`DEFAULT_CHARACTER_SET_SCHEMA` Nullable(String) ALIAS default_character_set_schema,
`DEFAULT_CHARACTER_SET_NAME` Nullable(String) ALIAS default_character_set_name,
`SQL_PATH` Nullable(String) ALIAS sql_path
) AS
SELECT
name AS catalog_name,
name AS schema_name,
'default' AS schema_owner,
NULL AS default_character_set_catalog,
NULL AS default_character_set_schema,
NULL AS default_character_set_name,
NULL AS sql_path
FROM system.databases

View File

@ -1,17 +0,0 @@
ATTACH VIEW tables
(
`table_catalog` String,
`table_schema` String,
`table_name` String,
`table_type` Enum8('BASE TABLE' = 1, 'VIEW' = 2, 'FOREIGN TABLE' = 3, 'LOCAL TEMPORARY' = 4, 'SYSTEM VIEW' = 5),
`TABLE_CATALOG` String ALIAS table_catalog,
`TABLE_SCHEMA` String ALIAS table_schema,
`TABLE_NAME` String ALIAS table_name,
`TABLE_TYPE` Enum8('BASE TABLE' = 1, 'VIEW' = 2, 'FOREIGN TABLE' = 3, 'LOCAL TEMPORARY' = 4, 'SYSTEM VIEW' = 5) ALIAS table_type
) AS
SELECT
database AS table_catalog,
database AS table_schema,
name AS table_name,
multiIf(is_temporary, 4, engine like '%View', 2, engine LIKE 'System%', 5, has_own_data = 0, 3, 1) AS table_type
FROM system.tables

View File

@ -1,36 +0,0 @@
ATTACH VIEW views
(
`table_catalog` String,
`table_schema` String,
`table_name` String,
`view_definition` String,
`check_option` String,
`is_updatable` Enum8('NO' = 0, 'YES' = 1),
`is_insertable_into` Enum8('NO' = 0, 'YES' = 1),
`is_trigger_updatable` Enum8('NO' = 0, 'YES' = 1),
`is_trigger_deletable` Enum8('NO' = 0, 'YES' = 1),
`is_trigger_insertable_into` Enum8('NO' = 0, 'YES' = 1),
`TABLE_CATALOG` String ALIAS table_catalog,
`TABLE_SCHEMA` String ALIAS table_schema,
`TABLE_NAME` String ALIAS table_name,
`VIEW_DEFINITION` String ALIAS view_definition,
`CHECK_OPTION` String ALIAS check_option,
`IS_UPDATABLE` Enum8('NO' = 0, 'YES' = 1) ALIAS is_updatable,
`IS_INSERTABLE_INTO` Enum8('NO' = 0, 'YES' = 1) ALIAS is_insertable_into,
`IS_TRIGGER_UPDATABLE` Enum8('NO' = 0, 'YES' = 1) ALIAS is_trigger_updatable,
`IS_TRIGGER_DELETABLE` Enum8('NO' = 0, 'YES' = 1) ALIAS is_trigger_deletable,
`IS_TRIGGER_INSERTABLE_INTO` Enum8('NO' = 0, 'YES' = 1) ALIAS is_trigger_insertable_into
) AS
SELECT
database AS table_catalog,
database AS table_schema,
name AS table_name,
as_select AS view_definition,
'NONE' AS check_option,
0 AS is_updatable,
engine = 'MaterializedView' AS is_insertable_into,
0 AS is_trigger_updatable,
0 AS is_trigger_deletable,
0 AS is_trigger_insertable_into
FROM system.tables
WHERE engine LIKE '%View'

View File

@ -3,20 +3,360 @@
#include <Storages/System/attachSystemTablesImpl.h>
#include <Parsers/ParserCreateQuery.h>
#include <Parsers/parseQuery.h>
#include <incbin.h>
#include "config.h"
/// Embedded SQL definitions
INCBIN(resource_schemata_sql, SOURCE_DIR "/src/Storages/System/InformationSchema/schemata.sql");
INCBIN(resource_tables_sql, SOURCE_DIR "/src/Storages/System/InformationSchema/tables.sql");
INCBIN(resource_views_sql, SOURCE_DIR "/src/Storages/System/InformationSchema/views.sql");
INCBIN(resource_columns_sql, SOURCE_DIR "/src/Storages/System/InformationSchema/columns.sql");
namespace DB
{
/// Below are SQL definitions for views in "information_schema". Perhaps it would be more aesthetic to have them in .sql files
/// and embed them here instead. In fact, it has been that way using INCBIN macros until #54773. The problem was that when
/// existing .sql files were changed, the build system did not recognize that this source (.cpp) file changed and instead used
/// cached object files from previous builds.
///
/// INCBIN is one of many libraries to embed external data. We might wait a little bit longer and try #embed (*) which should
/// solve the problem once and for all after 40 years.
///
/// (*) https://thephd.dev/finally-embed-in-c23
static constexpr std::string_view schemata = R"(
ATTACH VIEW schemata
(
`catalog_name` String,
`schema_name` String,
`schema_owner` String,
`default_character_set_catalog` Nullable(String),
`default_character_set_schema` Nullable(String),
`default_character_set_name` Nullable(String),
`sql_path` Nullable(String),
`CATALOG_NAME` String,
`SCHEMA_NAME` String,
`SCHEMA_OWNER` String,
`DEFAULT_CHARACTER_SET_CATALOG` Nullable(String),
`DEFAULT_CHARACTER_SET_SCHEMA` Nullable(String),
`DEFAULT_CHARACTER_SET_NAME` Nullable(String),
`SQL_PATH` Nullable(String)
) AS
SELECT
name AS catalog_name,
name AS schema_name,
'default' AS schema_owner,
NULL AS default_character_set_catalog,
NULL AS default_character_set_schema,
NULL AS default_character_set_name,
NULL AS sql_path,
catalog_name AS CATALOG_NAME,
schema_name AS SCHEMA_NAME,
schema_owner AS SCHEMA_OWNER,
default_character_set_catalog AS DEFAULT_CHARACTER_SET_CATALOG,
default_character_set_schema AS DEFAULT_CHARACTER_SET_SCHEMA,
default_character_set_name AS DEFAULT_CHARACTER_SET_NAME,
sql_path AS SQL_PATH
FROM system.databases
)";
static constexpr std::string_view tables = R"(
ATTACH VIEW tables
(
`table_catalog` String,
`table_schema` String,
`table_name` String,
`table_type` String,
`table_collation` Nullable(String),
`table_comment` Nullable(String),
`TABLE_CATALOG` String,
`TABLE_SCHEMA` String,
`TABLE_NAME` String,
`TABLE_TYPE` String,
`TABLE_COLLATION` Nullable(String),
`TABLE_COMMENT` Nullable(String)
) AS
SELECT
database AS table_catalog,
database AS table_schema,
name AS table_name,
multiIf(is_temporary, 'LOCAL TEMPORARY',
engine LIKE '%View', 'VIEW',
engine LIKE 'System%', 'SYSTEM VIEW',
has_own_data = 0, 'FOREIGN TABLE',
'BASE TABLE'
) AS table_type,
'utf8mb4_0900_ai_ci' AS table_collation,
comment AS table_comment,
table_catalog AS TABLE_CATALOG,
table_schema AS TABLE_SCHEMA,
table_name AS TABLE_NAME,
table_type AS TABLE_TYPE,
table_collation AS TABLE_COLLATION,
table_comment AS TABLE_COMMENT
FROM system.tables
)";
static constexpr std::string_view views = R"(
ATTACH VIEW views
(
`table_catalog` String,
`table_schema` String,
`table_name` String,
`view_definition` String,
`check_option` String,
`is_updatable` Enum8('NO' = 0, 'YES' = 1),
`is_insertable_into` Enum8('NO' = 0, 'YES' = 1),
`is_trigger_updatable` Enum8('NO' = 0, 'YES' = 1),
`is_trigger_deletable` Enum8('NO' = 0, 'YES' = 1),
`is_trigger_insertable_into` Enum8('NO' = 0, 'YES' = 1),
`TABLE_CATALOG` String,
`TABLE_SCHEMA` String,
`TABLE_NAME` String,
`VIEW_DEFINITION` String,
`CHECK_OPTION` String,
`IS_UPDATABLE` Enum8('NO' = 0, 'YES' = 1),
`IS_INSERTABLE_INTO` Enum8('NO' = 0, 'YES' = 1),
`IS_TRIGGER_UPDATABLE` Enum8('NO' = 0, 'YES' = 1),
`IS_TRIGGER_DELETABLE` Enum8('NO' = 0, 'YES' = 1),
`IS_TRIGGER_INSERTABLE_INTO` Enum8('NO' = 0, 'YES' = 1)
) AS
SELECT
database AS table_catalog,
database AS table_schema,
name AS table_name,
as_select AS view_definition,
'NONE' AS check_option,
0 AS is_updatable,
engine = 'MaterializedView' AS is_insertable_into,
0 AS is_trigger_updatable,
0 AS is_trigger_deletable,
0 AS is_trigger_insertable_into,
table_catalog AS TABLE_CATALOG,
table_schema AS TABLE_SCHEMA,
table_name AS TABLE_NAME,
view_definition AS VIEW_DEFINITION,
check_option AS CHECK_OPTION,
is_updatable AS IS_UPDATABLE,
is_insertable_into AS IS_INSERTABLE_INTO,
is_trigger_updatable AS IS_TRIGGER_UPDATABLE,
is_trigger_deletable AS IS_TRIGGER_DELETABLE,
is_trigger_insertable_into AS IS_TRIGGER_INSERTABLE_INTO
FROM system.tables
WHERE engine LIKE '%View'
)";
static constexpr std::string_view columns = R"(
ATTACH VIEW columns
(
`table_catalog` String,
`table_schema` String,
`table_name` String,
`column_name` String,
`ordinal_position` UInt64,
`column_default` String,
`is_nullable` String,
`data_type` String,
`character_maximum_length` Nullable(UInt64),
`character_octet_length` Nullable(UInt64),
`numeric_precision` Nullable(UInt64),
`numeric_precision_radix` Nullable(UInt64),
`numeric_scale` Nullable(UInt64),
`datetime_precision` Nullable(UInt64),
`character_set_catalog` Nullable(String),
`character_set_schema` Nullable(String),
`character_set_name` Nullable(String),
`collation_catalog` Nullable(String),
`collation_schema` Nullable(String),
`collation_name` Nullable(String),
`domain_catalog` Nullable(String),
`domain_schema` Nullable(String),
`domain_name` Nullable(String),
`column_comment` String,
`column_type` String,
`TABLE_CATALOG` String,
`TABLE_SCHEMA` String,
`TABLE_NAME` String,
`COLUMN_NAME` String,
`ORDINAL_POSITION` UInt64,
`COLUMN_DEFAULT` String,
`IS_NULLABLE` String,
`DATA_TYPE` String,
`CHARACTER_MAXIMUM_LENGTH` Nullable(UInt64),
`CHARACTER_OCTET_LENGTH` Nullable(UInt64),
`NUMERIC_PRECISION` Nullable(UInt64),
`NUMERIC_PRECISION_RADIX` Nullable(UInt64),
`NUMERIC_SCALE` Nullable(UInt64),
`DATETIME_PRECISION` Nullable(UInt64),
`CHARACTER_SET_CATALOG` Nullable(String),
`CHARACTER_SET_SCHEMA` Nullable(String),
`CHARACTER_SET_NAME` Nullable(String),
`COLLATION_CATALOG` Nullable(String),
`COLLATION_SCHEMA` Nullable(String),
`COLLATION_NAME` Nullable(String),
`DOMAIN_CATALOG` Nullable(String),
`DOMAIN_SCHEMA` Nullable(String),
`DOMAIN_NAME` Nullable(String),
`COLUMN_COMMENT` String,
`COLUMN_TYPE` String
) AS
SELECT
database AS table_catalog,
database AS table_schema,
table AS table_name,
name AS column_name,
position AS ordinal_position,
default_expression AS column_default,
type LIKE 'Nullable(%)' AS is_nullable,
type AS data_type,
character_octet_length AS character_maximum_length,
character_octet_length,
numeric_precision,
numeric_precision_radix,
numeric_scale,
datetime_precision,
NULL AS character_set_catalog,
NULL AS character_set_schema,
NULL AS character_set_name,
NULL AS collation_catalog,
NULL AS collation_schema,
NULL AS collation_name,
NULL AS domain_catalog,
NULL AS domain_schema,
NULL AS domain_name,
comment AS column_comment,
type AS column_type,
table_catalog AS TABLE_CATALOG,
table_schema AS TABLE_SCHEMA,
table_name AS TABLE_NAME,
column_name AS COLUMN_NAME,
ordinal_position AS ORDINAL_POSITION,
column_default AS COLUMN_DEFAULT,
is_nullable AS IS_NULLABLE,
data_type AS DATA_TYPE,
character_maximum_length AS CHARACTER_MAXIMUM_LENGTH,
character_octet_length AS CHARACTER_OCTET_LENGTH,
numeric_precision AS NUMERIC_PRECISION,
numeric_precision_radix AS NUMERIC_PRECISION_RADIX,
numeric_scale AS NUMERIC_SCALE,
datetime_precision AS DATETIME_PRECISION,
character_set_catalog AS CHARACTER_SET_CATALOG,
character_set_schema AS CHARACTER_SET_SCHEMA,
character_set_name AS CHARACTER_SET_NAME,
collation_catalog AS COLLATION_CATALOG,
collation_schema AS COLLATION_SCHEMA,
collation_name AS COLLATION_NAME,
domain_catalog AS DOMAIN_CATALOG,
domain_schema AS DOMAIN_SCHEMA,
domain_name AS DOMAIN_NAME,
column_comment AS COLUMN_COMMENT,
column_type AS COLUMN_TYPE
FROM system.columns
)";
static constexpr std::string_view key_column_usage = R"(
ATTACH VIEW key_column_usage
(
`constraint_catalog` String,
`constraint_schema` String,
`constraint_name` Nullable(String),
`table_catalog` String,
`table_schema` String,
`table_name` String,
`column_name` Nullable(String),
`ordinal_position` UInt32,
`position_in_unique_constraint` Nullable(UInt32),
`referenced_table_schema` Nullable(String),
`referenced_table_name` Nullable(String),
`referenced_column_name` Nullable(String),
`CONSTRAINT_CATALOG` Nullable(String),
`CONSTRAINT_SCHEMA` Nullable(String),
`CONSTRAINT_NAME` Nullable(String),
`TABLE_CATALOG` String,
`TABLE_SCHEMA` String,
`TABLE_NAME` String,
`COLUMN_NAME` Nullable(String),
`ORDINAL_POSITION` UInt32,
`POSITION_IN_UNIQUE_CONSTRAINT` Nullable(UInt32),
`REFERENCED_TABLE_SCHEMA` Nullable(String),
`REFERENCED_TABLE_NAME` Nullable(String),
`REFERENCED_COLUMN_NAME` Nullable(String)
) AS
SELECT
'def' AS constraint_catalog,
database AS constraint_schema,
'PRIMARY' AS constraint_name,
'def' AS table_catalog,
database AS table_schema,
table AS table_name,
name AS column_name,
1 AS ordinal_position,
NULL AS position_in_unique_constraint,
NULL AS referenced_table_schema,
NULL AS referenced_table_name,
NULL AS referenced_column_name,
constraint_catalog AS CONSTRAINT_CATALOG,
constraint_schema AS CONSTRAINT_SCHEMA,
constraint_name AS CONSTRAINT_NAME,
table_catalog AS TABLE_CATALOG,
table_schema AS TABLE_SCHEMA,
table_name AS TABLE_NAME,
column_name AS COLUMN_NAME,
ordinal_position AS ORDINAL_POSITION,
position_in_unique_constraint AS POSITION_IN_UNIQUE_CONSTRAINT,
referenced_table_schema AS REFERENCED_TABLE_SCHEMA,
referenced_table_name AS REFERENCED_TABLE_NAME,
referenced_column_name AS REFERENCED_COLUMN_NAME
FROM system.columns
WHERE is_in_primary_key;
)";
static constexpr std::string_view referential_constraints = R"(
ATTACH VIEW referential_constraints
(
`constraint_catalog` String,
`constraint_schema` String,
`constraint_name` Nullable(String),
`unique_constraint_catalog` String,
`unique_constraint_schema` String,
`unique_constraint_name` Nullable(String),
`match_option` String,
`update_rule` String,
`delete_rule` String,
`table_name` String,
`referenced_table_name` String,
`CONSTRAINT_CATALOG` String,
`CONSTRAINT_SCHEMA` String,
`CONSTRAINT_NAME` Nullable(String),
`UNIQUE_CONSTRAINT_CATALOG` String,
`UNIQUE_CONSTRAINT_SCHEMA` String,
`UNIQUE_CONSTRAINT_NAME` Nullable(String),
`MATCH_OPTION` String,
`UPDATE_RULE` String,
`DELETE_RULE` String,
`TABLE_NAME` String,
`REFERENCED_TABLE_NAME` String
) AS
SELECT
'' AS constraint_catalog,
NULL AS constraint_name,
'' AS constraint_schema,
'' AS unique_constraint_catalog,
NULL AS unique_constraint_name,
'' AS unique_constraint_schema,
'' AS match_option,
'' AS update_rule,
'' AS delete_rule,
'' AS table_name,
'' AS referenced_table_name,
constraint_catalog AS CONSTRAINT_CATALOG,
constraint_name AS CONSTRAINT_NAME,
constraint_schema AS CONSTRAINT_SCHEMA,
unique_constraint_catalog AS UNIQUE_CONSTRAINT_CATALOG,
unique_constraint_name AS UNIQUE_CONSTRAINT_NAME,
unique_constraint_schema AS UNIQUE_CONSTRAINT_SCHEMA,
match_option AS MATCH_OPTION,
update_rule AS UPDATE_RULE,
delete_rule AS DELETE_RULE,
table_name AS TABLE_NAME,
referenced_table_name AS REFERENCED_TABLE_NAME
WHERE false; -- make sure this view is always empty
)";
/// View structures are taken from http://www.contrib.andrew.cmu.edu/~shadow/sql/sql1992.txt
static void createInformationSchemaView(ContextMutablePtr context, IDatabase & database, const String & view_name, std::string_view query)
@ -62,10 +402,12 @@ static void createInformationSchemaView(ContextMutablePtr context, IDatabase & d
void attachInformationSchema(ContextMutablePtr context, IDatabase & information_schema_database)
{
createInformationSchemaView(context, information_schema_database, "schemata", std::string_view(reinterpret_cast<const char *>(gresource_schemata_sqlData), gresource_schemata_sqlSize));
createInformationSchemaView(context, information_schema_database, "tables", std::string_view(reinterpret_cast<const char *>(gresource_tables_sqlData), gresource_tables_sqlSize));
createInformationSchemaView(context, information_schema_database, "views", std::string_view(reinterpret_cast<const char *>(gresource_views_sqlData), gresource_views_sqlSize));
createInformationSchemaView(context, information_schema_database, "columns", std::string_view(reinterpret_cast<const char *>(gresource_columns_sqlData), gresource_columns_sqlSize));
createInformationSchemaView(context, information_schema_database, "schemata", schemata);
createInformationSchemaView(context, information_schema_database, "tables", tables);
createInformationSchemaView(context, information_schema_database, "views", views);
createInformationSchemaView(context, information_schema_database, "columns", columns);
createInformationSchemaView(context, information_schema_database, "key_column_usage", key_column_usage);
createInformationSchemaView(context, information_schema_database, "referential_constraints", referential_constraints);
}
}

View File

@ -1,37 +1,55 @@
COLUMNS
KEY_COLUMN_USAGE
REFERENTIAL_CONSTRAINTS
SCHEMATA
TABLES
VIEWS
columns
key_column_usage
referential_constraints
schemata
tables
views
COLUMNS
KEY_COLUMN_USAGE
REFERENTIAL_CONSTRAINTS
SCHEMATA
TABLES
VIEWS
columns
key_column_usage
referential_constraints
schemata
tables
views
INFORMATION_SCHEMA INFORMATION_SCHEMA default \N \N \N \N
information_schema information_schema default \N \N \N \N
default default mv VIEW
default default t FOREIGN TABLE
default default v VIEW
tmp LOCAL TEMPORARY
default default mv SELECT * FROM system.one NONE NO YES NO NO NO
default default v SELECT n, f FROM default.t NONE NO NO NO NO NO
default default mv default mv dummy 1 0 UInt8 \N \N 8 2 0 \N \N \N \N \N \N \N \N \N \N UInt8
default default t default t n 1 0 UInt64 \N \N 64 2 0 \N \N \N \N \N \N \N \N \N \N UInt64
default default t default t f 2 0 Float32 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N Float32
default default t default t s 3 0 String \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N String
default default t default t fs 4 0 FixedString(42) 42 42 \N \N \N \N \N \N \N \N \N \N \N \N \N FixedString(42)
default default t default t d 5 0 Decimal(9, 6) \N \N 9 10 6 \N \N \N \N \N \N \N \N \N \N Decimal(9, 6)
default default v default v n 1 1 Nullable(Int32) \N \N 32 2 0 \N \N \N \N \N \N \N \N \N \N Nullable(Int32)
default default v default v f 2 0 Float64 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N Float64
tmp tmp d 1 0 Date \N \N \N \N \N 0 \N \N \N \N \N \N \N \N \N Date
tmp tmp dt 2 0 DateTime \N \N \N \N \N 0 \N \N \N \N \N \N \N \N \N DateTime
tmp tmp dtms 3 0 DateTime64(3) \N \N \N \N \N 3 \N \N \N \N \N \N \N \N \N DateTime64(3)
INFORMATION_SCHEMA INFORMATION_SCHEMA default \N \N \N \N INFORMATION_SCHEMA INFORMATION_SCHEMA default \N \N \N \N
information_schema information_schema default \N \N \N \N information_schema information_schema default \N \N \N \N
default default kcu BASE TABLE utf8mb4_0900_ai_ci default default kcu BASE TABLE utf8mb4_0900_ai_ci
default default kcu2 BASE TABLE utf8mb4_0900_ai_ci default default kcu2 BASE TABLE utf8mb4_0900_ai_ci
default default mv VIEW utf8mb4_0900_ai_ci default default mv VIEW utf8mb4_0900_ai_ci
default default t FOREIGN TABLE utf8mb4_0900_ai_ci default default t FOREIGN TABLE utf8mb4_0900_ai_ci
default default v VIEW utf8mb4_0900_ai_ci default default v VIEW utf8mb4_0900_ai_ci
tmp LOCAL TEMPORARY utf8mb4_0900_ai_ci tmp LOCAL TEMPORARY utf8mb4_0900_ai_ci
default default mv SELECT * FROM system.one NONE NO YES NO NO NO default default mv SELECT * FROM system.one NONE NO YES NO NO NO
default default v SELECT n, f FROM default.t NONE NO NO NO NO NO default default v SELECT n, f FROM default.t NONE NO NO NO NO NO
default default kcu i 1 0 UInt32 \N \N 32 2 0 \N \N \N \N \N \N \N \N \N \N UInt32 default default kcu i 1 0 UInt32 \N \N 32 2 0 \N \N \N \N \N \N \N \N \N \N UInt32
default default kcu s 2 0 String \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N String default default kcu s 2 0 String \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N String
default default kcu2 i 1 0 UInt32 \N \N 32 2 0 \N \N \N \N \N \N \N \N \N \N UInt32 default default kcu2 i 1 0 UInt32 \N \N 32 2 0 \N \N \N \N \N \N \N \N \N \N UInt32
default default kcu2 d 2 0 Date \N \N \N \N \N 0 \N \N \N \N \N \N \N \N \N Date default default kcu2 d 2 0 Date \N \N \N \N \N 0 \N \N \N \N \N \N \N \N \N Date
default default kcu2 u 3 0 UUID \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N UUID default default kcu2 u 3 0 UUID \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N UUID
default default mv dummy 1 0 UInt8 \N \N 8 2 0 \N \N \N \N \N \N \N \N \N \N UInt8 default default mv dummy 1 0 UInt8 \N \N 8 2 0 \N \N \N \N \N \N \N \N \N \N UInt8
default default t n 1 0 UInt64 \N \N 64 2 0 \N \N \N \N \N \N \N \N \N \N UInt64 default default t n 1 0 UInt64 \N \N 64 2 0 \N \N \N \N \N \N \N \N \N \N UInt64
default default t f 2 0 Float32 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N Float32 default default t f 2 0 Float32 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N Float32
default default t s 3 0 String \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N String default default t s 3 0 String \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N String
default default t fs 4 0 FixedString(42) 42 42 \N \N \N \N \N \N \N \N \N \N \N \N \N FixedString(42) default default t fs 4 0 FixedString(42) 42 42 \N \N \N \N \N \N \N \N \N \N \N \N \N FixedString(42)
default default t d 5 0 Decimal(9, 6) \N \N 9 10 6 \N \N \N \N \N \N \N \N \N \N Decimal(9, 6) default default t d 5 0 Decimal(9, 6) \N \N 9 10 6 \N \N \N \N \N \N \N \N \N \N Decimal(9, 6)
default default v n 1 1 Nullable(Int32) \N \N 32 2 0 \N \N \N \N \N \N \N \N \N \N Nullable(Int32) default default v n 1 1 Nullable(Int32) \N \N 32 2 0 \N \N \N \N \N \N \N \N \N \N Nullable(Int32)
default default v f 2 0 Float64 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N Float64 default default v f 2 0 Float64 \N \N \N \N \N \N \N \N \N \N \N \N \N \N \N Float64
tmp d 1 0 Date \N \N \N \N \N 0 \N \N \N \N \N \N \N \N \N Date tmp d 1 0 Date \N \N \N \N \N 0 \N \N \N \N \N \N \N \N \N Date
tmp dt 2 0 DateTime \N \N \N \N \N 0 \N \N \N \N \N \N \N \N \N DateTime tmp dt 2 0 DateTime \N \N \N \N \N 0 \N \N \N \N \N \N \N \N \N DateTime
tmp dtms 3 0 DateTime64(3) \N \N \N \N \N 3 \N \N \N \N \N \N \N \N \N DateTime64(3) tmp dtms 3 0 DateTime64(3) \N \N \N \N \N 3 \N \N \N \N \N \N \N \N \N DateTime64(3)
1
1
def default PRIMARY def default kcu i 1 \N \N \N \N def default PRIMARY def default kcu i 1 \N \N \N \N
def default PRIMARY def default kcu2 d 1 \N \N \N \N def default PRIMARY def default kcu2 d 1 \N \N \N \N
def default PRIMARY def default kcu2 u 1 \N \N \N \N def default PRIMARY def default kcu2 u 1 \N \N \N \N

View File

@ -5,27 +5,37 @@ DROP TABLE IF EXISTS t;
DROP VIEW IF EXISTS v;
DROP VIEW IF EXISTS mv;
DROP TABLE IF EXISTS tmp;
DROP TABLE IF EXISTS kcu;
DROP TABLE IF EXISTS kcu2;
CREATE TABLE t (n UInt64, f Float32, s String, fs FixedString(42), d Decimal(9, 6)) ENGINE=Memory;
CREATE VIEW v (n Nullable(Int32), f Float64) AS SELECT n, f FROM t;
CREATE MATERIALIZED VIEW mv ENGINE=Null AS SELECT * FROM system.one;
CREATE TEMPORARY TABLE tmp (d Date, dt DateTime, dtms DateTime64(3));
CREATE TABLE kcu (i UInt32, s String) ENGINE MergeTree ORDER BY i;
CREATE TABLE kcu2 (i UInt32, d Date, u UUID) ENGINE MergeTree ORDER BY (u, d);
-- FIXME #28687
SELECT * FROM information_schema.schemata WHERE schema_name ilike 'information_schema';
-- SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE (TABLE_SCHEMA=currentDatabase() OR TABLE_SCHEMA='') AND TABLE_NAME NOT LIKE '%inner%';
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE (table_schema=currentDatabase() OR table_schema='') AND table_name NOT LIKE '%inner%';
SELECT * FROM information_schema.views WHERE table_schema=currentDatabase();
-- SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_SCHEMA=currentDatabase() OR TABLE_SCHEMA='') AND TABLE_NAME NOT LIKE '%inner%';
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE (table_schema=currentDatabase() OR table_schema='') AND table_name NOT LIKE '%inner%';
SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE (table_schema = currentDatabase() OR table_schema = '') AND table_name NOT LIKE '%inner%';
SELECT * FROM information_schema.views WHERE table_schema = currentDatabase();
-- SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE (TABLE_SCHEMA=currentDatabase() OR TABLE_SCHEMA='') AND TABLE_NAME NOT LIKE '%inner%'
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE (table_schema = currentDatabase() OR table_schema = '') AND table_name NOT LIKE '%inner%';
-- mixed upper/lowercase schema and table name:
SELECT count() FROM information_schema.TABLES WHERE table_schema=currentDatabase() AND table_name = 't';
SELECT count() FROM INFORMATION_SCHEMA.tables WHERE table_schema=currentDatabase() AND table_name = 't';
SELECT count() FROM INFORMATION_schema.tables WHERE table_schema=currentDatabase() AND table_name = 't'; -- { serverError UNKNOWN_DATABASE }
SELECT count() FROM information_schema.taBLES WHERE table_schema=currentDatabase() AND table_name = 't'; -- { serverError UNKNOWN_TABLE }
SELECT count() FROM information_schema.TABLES WHERE table_schema = currentDatabase() AND table_name = 't';
SELECT count() FROM INFORMATION_SCHEMA.tables WHERE table_schema = currentDatabase() AND table_name = 't';
SELECT count() FROM INFORMATION_schema.tables WHERE table_schema = currentDatabase() AND table_name = 't'; -- { serverError UNKNOWN_DATABASE }
SELECT count() FROM information_schema.taBLES WHERE table_schema =currentDatabase() AND table_name = 't'; -- { serverError UNKNOWN_TABLE }
SELECT * FROM information_schema.key_column_usage WHERE table_schema = currentDatabase() AND table_name = 'kcu';
SELECT * FROM information_schema.key_column_usage WHERE table_schema = currentDatabase() AND table_name = 'kcu2';
SELECT * FROM information_schema.referential_constraints;
drop view mv;
drop view v;
drop table t;
drop table kcu;
drop table kcu2;

View File

@ -1,6 +1,6 @@
CREATE DATABASE INFORMATION_SCHEMA\nENGINE = Memory
CREATE VIEW INFORMATION_SCHEMA.COLUMNS\n(\n `table_catalog` String,\n `table_schema` String,\n `table_name` String,\n `TABLE_SCHEMA` String,\n `TABLE_NAME` String,\n `column_name` String,\n `ordinal_position` UInt64,\n `column_default` String,\n `is_nullable` String,\n `data_type` String,\n `character_maximum_length` Nullable(UInt64),\n `character_octet_length` Nullable(UInt64),\n `numeric_precision` Nullable(UInt64),\n `numeric_precision_radix` Nullable(UInt64),\n `numeric_scale` Nullable(UInt64),\n `datetime_precision` Nullable(UInt64),\n `character_set_catalog` Nullable(String),\n `character_set_schema` Nullable(String),\n `character_set_name` Nullable(String),\n `collation_catalog` Nullable(String),\n `collation_schema` Nullable(String),\n `collation_name` Nullable(String),\n `domain_catalog` Nullable(String),\n `domain_schema` Nullable(String),\n `domain_name` Nullable(String),\n `column_comment` String,\n `column_type` String,\n `TABLE_CATALOG` String ALIAS table_catalog,\n `COLUMN_NAME` String ALIAS column_name,\n `ORDINAL_POSITION` UInt64 ALIAS ordinal_position,\n `COLUMN_DEFAULT` String ALIAS column_default,\n `IS_NULLABLE` String ALIAS is_nullable,\n `DATA_TYPE` String ALIAS data_type,\n `CHARACTER_MAXIMUM_LENGTH` Nullable(UInt64) ALIAS character_maximum_length,\n `CHARACTER_OCTET_LENGTH` Nullable(UInt64) ALIAS character_octet_length,\n `NUMERIC_PRECISION` Nullable(UInt64) ALIAS numeric_precision,\n `NUMERIC_PRECISION_RADIX` Nullable(UInt64) ALIAS numeric_precision_radix,\n `NUMERIC_SCALE` Nullable(UInt64) ALIAS numeric_scale,\n `DATETIME_PRECISION` Nullable(UInt64) ALIAS datetime_precision,\n `CHARACTER_SET_CATALOG` Nullable(String) ALIAS character_set_catalog,\n `CHARACTER_SET_SCHEMA` Nullable(String) ALIAS character_set_schema,\n `CHARACTER_SET_NAME` Nullable(String) ALIAS character_set_name,\n `COLLATION_CATALOG` Nullable(String) ALIAS collation_catalog,\n `COLLATION_SCHEMA` Nullable(String) ALIAS collation_schema,\n `COLLATION_NAME` Nullable(String) ALIAS collation_name,\n `DOMAIN_CATALOG` Nullable(String) ALIAS domain_catalog,\n `DOMAIN_SCHEMA` Nullable(String) ALIAS domain_schema,\n `DOMAIN_NAME` Nullable(String) ALIAS domain_name,\n `COLUMN_COMMENT` String ALIAS column_comment,\n `COLUMN_TYPE` String ALIAS column_type\n) AS\nSELECT\n database AS table_catalog,\n database AS table_schema,\n database AS TABLE_SCHEMA,\n table AS table_name,\n table AS TABLE_NAME,\n name AS column_name,\n position AS ordinal_position,\n default_expression AS column_default,\n type LIKE \'Nullable(%)\' AS is_nullable,\n type AS data_type,\n character_octet_length AS character_maximum_length,\n character_octet_length,\n numeric_precision,\n numeric_precision_radix,\n numeric_scale,\n datetime_precision,\n NULL AS character_set_catalog,\n NULL AS character_set_schema,\n NULL AS character_set_name,\n NULL AS collation_catalog,\n NULL AS collation_schema,\n NULL AS collation_name,\n NULL AS domain_catalog,\n NULL AS domain_schema,\n NULL AS domain_name,\n comment AS column_comment,\n type AS column_type\nFROM system.columns
CREATE VIEW INFORMATION_SCHEMA.TABLES (`table_catalog` String, `table_schema` String, `table_name` String, `table_type` Enum8(\'BASE TABLE\' = 1, \'VIEW\' = 2, \'FOREIGN TABLE\' = 3, \'LOCAL TEMPORARY\' = 4, \'SYSTEM VIEW\' = 5), `TABLE_CATALOG` String ALIAS table_catalog, `TABLE_SCHEMA` String ALIAS table_schema, `TABLE_NAME` String ALIAS table_name, `TABLE_TYPE` Enum8(\'BASE TABLE\' = 1, \'VIEW\' = 2, \'FOREIGN TABLE\' = 3, \'LOCAL TEMPORARY\' = 4, \'SYSTEM VIEW\' = 5) ALIAS table_type) AS SELECT database AS table_catalog, database AS table_schema, name AS table_name, multiIf(is_temporary, 4, engine LIKE \'%View\', 2, engine LIKE \'System%\', 5, has_own_data = 0, 3, 1) AS table_type FROM system.tables
CREATE VIEW INFORMATION_SCHEMA.tables (`table_catalog` String, `table_schema` String, `table_name` String, `table_type` Enum8(\'BASE TABLE\' = 1, \'VIEW\' = 2, \'FOREIGN TABLE\' = 3, \'LOCAL TEMPORARY\' = 4, \'SYSTEM VIEW\' = 5), `TABLE_CATALOG` String ALIAS table_catalog, `TABLE_SCHEMA` String ALIAS table_schema, `TABLE_NAME` String ALIAS table_name, `TABLE_TYPE` Enum8(\'BASE TABLE\' = 1, \'VIEW\' = 2, \'FOREIGN TABLE\' = 3, \'LOCAL TEMPORARY\' = 4, \'SYSTEM VIEW\' = 5) ALIAS table_type) AS SELECT database AS table_catalog, database AS table_schema, name AS table_name, multiIf(is_temporary, 4, engine LIKE \'%View\', 2, engine LIKE \'System%\', 5, has_own_data = 0, 3, 1) AS table_type FROM system.tables
CREATE VIEW information_schema.TABLES (`table_catalog` String, `table_schema` String, `table_name` String, `table_type` Enum8(\'BASE TABLE\' = 1, \'VIEW\' = 2, \'FOREIGN TABLE\' = 3, \'LOCAL TEMPORARY\' = 4, \'SYSTEM VIEW\' = 5), `TABLE_CATALOG` String ALIAS table_catalog, `TABLE_SCHEMA` String ALIAS table_schema, `TABLE_NAME` String ALIAS table_name, `TABLE_TYPE` Enum8(\'BASE TABLE\' = 1, \'VIEW\' = 2, \'FOREIGN TABLE\' = 3, \'LOCAL TEMPORARY\' = 4, \'SYSTEM VIEW\' = 5) ALIAS table_type) AS SELECT database AS table_catalog, database AS table_schema, name AS table_name, multiIf(is_temporary, 4, engine LIKE \'%View\', 2, engine LIKE \'System%\', 5, has_own_data = 0, 3, 1) AS table_type FROM system.tables
CREATE VIEW information_schema.tables (`table_catalog` String, `table_schema` String, `table_name` String, `table_type` Enum8(\'BASE TABLE\' = 1, \'VIEW\' = 2, \'FOREIGN TABLE\' = 3, \'LOCAL TEMPORARY\' = 4, \'SYSTEM VIEW\' = 5), `TABLE_CATALOG` String ALIAS table_catalog, `TABLE_SCHEMA` String ALIAS table_schema, `TABLE_NAME` String ALIAS table_name, `TABLE_TYPE` Enum8(\'BASE TABLE\' = 1, \'VIEW\' = 2, \'FOREIGN TABLE\' = 3, \'LOCAL TEMPORARY\' = 4, \'SYSTEM VIEW\' = 5) ALIAS table_type) AS SELECT database AS table_catalog, database AS table_schema, name AS table_name, multiIf(is_temporary, 4, engine LIKE \'%View\', 2, engine LIKE \'System%\', 5, has_own_data = 0, 3, 1) AS table_type FROM system.tables
CREATE VIEW INFORMATION_SCHEMA.COLUMNS\n(\n `table_catalog` String,\n `table_schema` String,\n `table_name` String,\n `column_name` String,\n `ordinal_position` UInt64,\n `column_default` String,\n `is_nullable` String,\n `data_type` String,\n `character_maximum_length` Nullable(UInt64),\n `character_octet_length` Nullable(UInt64),\n `numeric_precision` Nullable(UInt64),\n `numeric_precision_radix` Nullable(UInt64),\n `numeric_scale` Nullable(UInt64),\n `datetime_precision` Nullable(UInt64),\n `character_set_catalog` Nullable(String),\n `character_set_schema` Nullable(String),\n `character_set_name` Nullable(String),\n `collation_catalog` Nullable(String),\n `collation_schema` Nullable(String),\n `collation_name` Nullable(String),\n `domain_catalog` Nullable(String),\n `domain_schema` Nullable(String),\n `domain_name` Nullable(String),\n `column_comment` String,\n `column_type` String,\n `TABLE_CATALOG` String,\n `TABLE_SCHEMA` String,\n `TABLE_NAME` String,\n `COLUMN_NAME` String,\n `ORDINAL_POSITION` UInt64,\n `COLUMN_DEFAULT` String,\n `IS_NULLABLE` String,\n `DATA_TYPE` String,\n `CHARACTER_MAXIMUM_LENGTH` Nullable(UInt64),\n `CHARACTER_OCTET_LENGTH` Nullable(UInt64),\n `NUMERIC_PRECISION` Nullable(UInt64),\n `NUMERIC_PRECISION_RADIX` Nullable(UInt64),\n `NUMERIC_SCALE` Nullable(UInt64),\n `DATETIME_PRECISION` Nullable(UInt64),\n `CHARACTER_SET_CATALOG` Nullable(String),\n `CHARACTER_SET_SCHEMA` Nullable(String),\n `CHARACTER_SET_NAME` Nullable(String),\n `COLLATION_CATALOG` Nullable(String),\n `COLLATION_SCHEMA` Nullable(String),\n `COLLATION_NAME` Nullable(String),\n `DOMAIN_CATALOG` Nullable(String),\n `DOMAIN_SCHEMA` Nullable(String),\n `DOMAIN_NAME` Nullable(String),\n `COLUMN_COMMENT` String,\n `COLUMN_TYPE` String\n) AS\nSELECT\n database AS table_catalog,\n database AS table_schema,\n table AS table_name,\n name AS column_name,\n position AS ordinal_position,\n default_expression AS column_default,\n type LIKE \'Nullable(%)\' AS is_nullable,\n type AS data_type,\n character_octet_length AS character_maximum_length,\n character_octet_length,\n numeric_precision,\n numeric_precision_radix,\n numeric_scale,\n datetime_precision,\n NULL AS character_set_catalog,\n NULL AS character_set_schema,\n NULL AS character_set_name,\n NULL AS collation_catalog,\n NULL AS collation_schema,\n NULL AS collation_name,\n NULL AS domain_catalog,\n NULL AS domain_schema,\n NULL AS domain_name,\n comment AS column_comment,\n type AS column_type,\n table_catalog AS TABLE_CATALOG,\n table_schema AS TABLE_SCHEMA,\n table_name AS TABLE_NAME,\n column_name AS COLUMN_NAME,\n ordinal_position AS ORDINAL_POSITION,\n column_default AS COLUMN_DEFAULT,\n is_nullable AS IS_NULLABLE,\n data_type AS DATA_TYPE,\n character_maximum_length AS CHARACTER_MAXIMUM_LENGTH,\n character_octet_length AS CHARACTER_OCTET_LENGTH,\n numeric_precision AS NUMERIC_PRECISION,\n numeric_precision_radix AS NUMERIC_PRECISION_RADIX,\n numeric_scale AS NUMERIC_SCALE,\n datetime_precision AS DATETIME_PRECISION,\n character_set_catalog AS CHARACTER_SET_CATALOG,\n character_set_schema AS CHARACTER_SET_SCHEMA,\n character_set_name AS CHARACTER_SET_NAME,\n collation_catalog AS COLLATION_CATALOG,\n collation_schema AS COLLATION_SCHEMA,\n collation_name AS COLLATION_NAME,\n domain_catalog AS DOMAIN_CATALOG,\n domain_schema AS DOMAIN_SCHEMA,\n domain_name AS DOMAIN_NAME,\n column_comment AS COLUMN_COMMENT,\n column_type AS COLUMN_TYPE\nFROM system.columns
CREATE VIEW INFORMATION_SCHEMA.TABLES (`table_catalog` String, `table_schema` String, `table_name` String, `table_type` String, `table_collation` Nullable(String), `table_comment` Nullable(String), `TABLE_CATALOG` String, `TABLE_SCHEMA` String, `TABLE_NAME` String, `TABLE_TYPE` String, `TABLE_COLLATION` Nullable(String), `TABLE_COMMENT` Nullable(String)) AS SELECT database AS table_catalog, database AS table_schema, name AS table_name, multiIf(is_temporary, \'LOCAL TEMPORARY\', engine LIKE \'%View\', \'VIEW\', engine LIKE \'System%\', \'SYSTEM VIEW\', has_own_data = 0, \'FOREIGN TABLE\', \'BASE TABLE\') AS table_type, \'utf8mb4_0900_ai_ci\' AS table_collation, comment AS table_comment, table_catalog AS TABLE_CATALOG, table_schema AS TABLE_SCHEMA, table_name AS TABLE_NAME, table_type AS TABLE_TYPE, table_collation AS TABLE_COLLATION, table_comment AS TABLE_COMMENT FROM system.tables
CREATE VIEW INFORMATION_SCHEMA.tables (`table_catalog` String, `table_schema` String, `table_name` String, `table_type` String, `table_collation` Nullable(String), `table_comment` Nullable(String), `TABLE_CATALOG` String, `TABLE_SCHEMA` String, `TABLE_NAME` String, `TABLE_TYPE` String, `TABLE_COLLATION` Nullable(String), `TABLE_COMMENT` Nullable(String)) AS SELECT database AS table_catalog, database AS table_schema, name AS table_name, multiIf(is_temporary, \'LOCAL TEMPORARY\', engine LIKE \'%View\', \'VIEW\', engine LIKE \'System%\', \'SYSTEM VIEW\', has_own_data = 0, \'FOREIGN TABLE\', \'BASE TABLE\') AS table_type, \'utf8mb4_0900_ai_ci\' AS table_collation, comment AS table_comment, table_catalog AS TABLE_CATALOG, table_schema AS TABLE_SCHEMA, table_name AS TABLE_NAME, table_type AS TABLE_TYPE, table_collation AS TABLE_COLLATION, table_comment AS TABLE_COMMENT FROM system.tables
CREATE VIEW information_schema.TABLES (`table_catalog` String, `table_schema` String, `table_name` String, `table_type` String, `table_collation` Nullable(String), `table_comment` Nullable(String), `TABLE_CATALOG` String, `TABLE_SCHEMA` String, `TABLE_NAME` String, `TABLE_TYPE` String, `TABLE_COLLATION` Nullable(String), `TABLE_COMMENT` Nullable(String)) AS SELECT database AS table_catalog, database AS table_schema, name AS table_name, multiIf(is_temporary, \'LOCAL TEMPORARY\', engine LIKE \'%View\', \'VIEW\', engine LIKE \'System%\', \'SYSTEM VIEW\', has_own_data = 0, \'FOREIGN TABLE\', \'BASE TABLE\') AS table_type, \'utf8mb4_0900_ai_ci\' AS table_collation, comment AS table_comment, table_catalog AS TABLE_CATALOG, table_schema AS TABLE_SCHEMA, table_name AS TABLE_NAME, table_type AS TABLE_TYPE, table_collation AS TABLE_COLLATION, table_comment AS TABLE_COMMENT FROM system.tables
CREATE VIEW information_schema.tables (`table_catalog` String, `table_schema` String, `table_name` String, `table_type` String, `table_collation` Nullable(String), `table_comment` Nullable(String), `TABLE_CATALOG` String, `TABLE_SCHEMA` String, `TABLE_NAME` String, `TABLE_TYPE` String, `TABLE_COLLATION` Nullable(String), `TABLE_COMMENT` Nullable(String)) AS SELECT database AS table_catalog, database AS table_schema, name AS table_name, multiIf(is_temporary, \'LOCAL TEMPORARY\', engine LIKE \'%View\', \'VIEW\', engine LIKE \'System%\', \'SYSTEM VIEW\', has_own_data = 0, \'FOREIGN TABLE\', \'BASE TABLE\') AS table_type, \'utf8mb4_0900_ai_ci\' AS table_collation, comment AS table_comment, table_catalog AS TABLE_CATALOG, table_schema AS TABLE_SCHEMA, table_name AS TABLE_NAME, table_type AS TABLE_TYPE, table_collation AS TABLE_COLLATION, table_comment AS TABLE_COMMENT FROM system.tables