Information schema

    Table of contents

    When the user management is enabled, accessing the information_schema is open to all users and it does not require any privileges.

    However, being able to query information_schema tables will not allow the user to retrieve all the rows in the table, as it can contain information related to tables over which the connected user does not have any privileges. The only rows that will be returned will be the ones the user is allowed to access.

    For example, if the user john has any privilege on the doc.books table but no privilege at all on doc.locations, when john issues a SELECT * FROM information_schema.tables statement, the tables information related to the doc.locations table will not be returned.

    Virtual tables

    The information_schema.tables virtual table can be queried to get a list of all available tables and views and their settings, such as number of shards or number of replicas.

    The table also contains additional information such as the specified and partition columns:

    1. cr> SELECT table_name, clustered_by, partitioned_by
    2. ... FROM information_schema.tables
    3. ... WHERE table_schema = 'doc'
    4. ... ORDER BY table_schema ASC, table_name ASC;
    5. +-------------------+--------------+----------------+
    6. | table_name | clustered_by | partitioned_by |
    7. +-------------------+--------------+----------------+
    8. | galaxies | NULL | NULL |
    9. | locations | id | NULL |
    10. | partitioned_table | _id | ["date"] |
    11. | quotes | id | NULL |
    12. +-------------------+--------------+----------------+
    13. SELECT 4 rows in set (... sec)

    Schema

    settings

    Table settings specify configuration parameters for tables. Some settings can be set during Cluster runtime and others are only applied on cluster restart.

    This list of table settings in shows detailed information of each parameter.

    Table parameters can be applied with CREATE TABLE on creation of a table. With ALTER TABLE they can be set on already existing tables.

    The following statement creates a new table and sets the refresh interval of shards to 500 ms and sets the shard allocation for primary shards only:

    1. cr> create table parameterized_table (id integer, content text)
    2. ... with ("refresh_interval"=500, "routing.allocation.enable"='primaries');
    3. CREATE OK, 1 row affected (... sec)

    The settings can be verified by querying information_schema.tables:

    1. cr> select settings['routing']['allocation']['enable'] as alloc_enable,
    2. ... settings['refresh_interval'] as refresh_interval
    3. ... from information_schema.tables
    4. ... where table_name='parameterized_table';
    5. +--------------+------------------+
    6. | alloc_enable | refresh_interval |
    7. +--------------+------------------+
    8. | primaries | 500 |
    9. +--------------+------------------+
    10. SELECT 1 row in set (... sec)

    On existing tables this needs to be done with ALTER TABLE statement:

    1. cr> alter table parameterized_table
    2. ... set ("routing.allocation.enable"='none');
    3. ALTER OK, -1 rows affected (... sec)

    views

    The table information_schema.views contains the name, definition and options of all available views.

    1. cr> SELECT table_schema, table_name, view_definition
    2. ... FROM information_schema.views
    3. ... ORDER BY table_schema ASC, table_name ASC;
    4. +--------------+------------+-------------------------+
    5. | table_schema | table_name | view_definition |
    6. +--------------+------------+-------------------------+
    7. | doc | galaxies | SELECT |
    8. | | | "id" |
    9. | | | , "name" |
    10. | | | , "description" |
    11. | | | FROM "locations" |
    12. | | | WHERE "kind" = 'Galaxy' |
    13. +--------------+------------+-------------------------+
    14. SELECT 1 row in set (... sec)

    Schema

    Name

    Description

    Data Type

    table_catalog

    The catalog of the table of the view (refers to table_schema)

    TEXT

    table_schema

    The schema of the table of the view

    TEXT

    table_name

    The name of the table of the view

    TEXT

    view_definition

    The SELECT statement that defines the view

    TEXT

    check_option

    Not applicable for CrateDB, always return NONE

    TEXT

    is_updatable

    Whether the view is updatable. Not applicable for CrateDB, always returns FALSE

    BOOLEAN

    owner

    The user that created the view

    TEXT

    Note

    If you drop the table of a view, the view will still exist and show up in the information_schema.tables and information_schema.views tables.

    columns

    This table can be queried to get a list of all available columns of all tables and views and their definition like data type and ordinal position inside the table:

    1. cr> select table_name, column_name, ordinal_position as pos, data_type
    2. ... where table_schema = 'doc' and table_name not like 'my_table%'
    3. ... order by table_name asc, column_name asc;
    4. +-------------------+--------------------------------+-----+--------------------------+
    5. | table_name | column_name | pos | data_type |
    6. +-------------------+--------------------------------+-----+--------------------------+
    7. | locations | date | 3 | timestamp with time zone |
    8. | locations | description | 6 | text |
    9. | locations | id | 1 | integer |
    10. | locations | information | 11 | object_array |
    11. | locations | information['evolution_level'] | 12 | smallint |
    12. | locations | information['population'] | 13 | bigint |
    13. | locations | inhabitants | 7 | object |
    14. | locations | inhabitants['description'] | 8 | text |
    15. | locations | inhabitants['interests'] | 9 | text_array |
    16. | locations | inhabitants['name'] | 10 | text |
    17. | locations | landmarks | 14 | text_array |
    18. | locations | name | 2 | text |
    19. | locations | position | 5 | integer |
    20. | partitioned_table | date | 3 | timestamp with time zone |
    21. | partitioned_table | id | 1 | bigint |
    22. | partitioned_table | title | 2 | text |
    23. | quotes | id | 1 | integer |
    24. | quotes | quote | 2 | text |
    25. +-------------------+--------------------------------+-----+--------------------------+
    26. SELECT 19 rows in set (... sec)

    You can even query this table’s own columns (attention: this might lead to infinite recursion of your mind, beware!):

    Schema

    This table can be queried to get a list of all defined table constraints, their type, name and which table they are defined in.

    Note

    Currently only PRIMARY_KEY constraints are supported.

    1. cr> select table_schema, table_name, constraint_name, constraint_type as type
    2. ... from information_schema.table_constraints
    3. ... where table_name = 'tables'
    4. ... or table_name = 'quotes'
    5. ... or table_name = 'documents'
    6. ... or table_name = 'tbl'
    7. ... order by table_schema desc, table_name asc limit 10;
    8. +--------------------+------------+-...------------------+-------------+
    9. | table_schema | table_name | constraint_name | type |
    10. +--------------------+------------+-...------------------+-------------+
    11. | information_schema | tables | tables_pk | PRIMARY KEY |
    12. | doc | quotes | quotes_pk | PRIMARY KEY |
    13. | doc | tbl | doc_tbl_col_not_null | CHECK |
    14. +--------------------+------------+-...------------------+-------------+
    15. SELECT 3 rows in set (... sec)

    key_column_usage

    This table may be queried to retrieve primary key information from all user tables:

    1. cr> select constraint_name, table_name, column_name, ordinal_position
    2. ... from information_schema.key_column_usage
    3. ... where table_name = 'students'
    4. +-----------------+------------+-------------+------------------+
    5. | constraint_name | table_name | column_name | ordinal_position |
    6. +-----------------+------------+-------------+------------------+
    7. | students_pk | students | id | 1 |
    8. | students_pk | students | department | 2 |
    9. +-----------------+------------+-------------+------------------+
    10. SELECT 2 rows in set (... sec)

    Schema

    Name

    Description

    Data Type

    constraint_catalog

    Refers to table_catalog

    TEXT

    constraint_schema

    Refers to table_schema

    TEXT

    constraint_name

    Name of the constraint

    TEXT

    table_catalog

    Refers to table_schema

    TEXT

    table_schema

    Name of the schema that contains the table that contains the constraint

    TEXT

    table_name

    Name of the table that contains the constraint

    column_name

    Name of the column that contains the constraint

    TEXT

    ordinal_position

    Position of the column within the contraint (starts with 1)

    INTEGER

    table_partitions

    This table can be queried to get information about all , Each partition of a table is represented as one row. The row contains the information table name, schema name, partition ident, and the values of the partition. values is a key-value object with the partition column (or columns) as key(s) and the corresponding value as value(s).

    1. cr> insert into a_partitioned_table (id, content) values (1, 'content_a');
    2. INSERT OK, 1 row affected (... sec)
    1. cr> alter table a_partitioned_table set (number_of_shards=5);
    1. cr> insert into a_partitioned_table (id, content) values (2, 'content_b');
    2. INSERT OK, 1 row affected (... sec)

    The following example shows a table where the column content of table a_partitioned_table has been used to partition the table. The table has two partitions. The partitions are introduced when data is inserted where content is content_a, and content_b.:

    1. cr> select table_name, table_schema as schema, partition_ident, "values"
    2. ... from information_schema.table_partitions
    3. ... order by table_name, partition_ident;
    4. +---------------------+--------+--------------------+--------------------------+
    5. | table_name | schema | partition_ident | values |
    6. +---------------------+--------+--------------------+--------------------------+
    7. | a_partitioned_table | doc | 04566rreehimst2vc4 | {"content": "content_a"} |
    8. | a_partitioned_table | doc | 04566rreehimst2vc8 | {"content": "content_b"} |
    9. +---------------------+--------+--------------------+--------------------------+
    10. SELECT 2 rows in set (... sec)

    The second partition has been created after the number of shards for future partitions have been changed on the partitioned table, so they show 5 instead of 4:

    The routines table contains tokenizers, token-filters, char-filters, custom analyzers created by CREATE ANALYZER statements (see ), and functions created by CREATE FUNCTION statements:

    1. cr> select routine_name, routine_type
    2. ... from information_schema.routines
    3. ... group by routine_name, routine_type
    4. +----------------------+--------------+
    5. | routine_name | routine_type |
    6. +----------------------+--------------+
    7. | PathHierarchy | TOKENIZER |
    8. | apostrophe | TOKEN_FILTER |
    9. | arabic | ANALYZER |
    10. | arabic_normalization | TOKEN_FILTER |
    11. | arabic_stem | TOKEN_FILTER |
    12. +----------------------+--------------+
    13. SELECT 5 rows in set (... sec)

    For example you can use this table to list existing tokenizers like this:

    1. cr> select routine_name
    2. ... from information_schema.routines
    3. ... where routine_type='TOKENIZER'
    4. ... order by routine_name asc limit 10;
    5. +----------------+
    6. | routine_name |
    7. +----------------+
    8. | PathHierarchy |
    9. | char_group |
    10. | classic |
    11. | edge_ngram |
    12. | keyword |
    13. | letter |
    14. | lowercase |
    15. | ngram |
    16. | path_hierarchy |
    17. | pattern |
    18. +----------------+
    19. SELECT 10 rows in set (... sec)

    Or get an overview of how many routines and routine types are available:

    1. cr> select count(*), routine_type
    2. ... from information_schema.routines
    3. ... group by routine_type
    4. ... order by routine_type;
    5. +----------+--------------+
    6. | count(*) | routine_type |
    7. +----------+--------------+
    8. | 45 | ANALYZER |
    9. | 3 | CHAR_FILTER |
    10. | 16 | TOKENIZER |
    11. | 62 | TOKEN_FILTER |
    12. +----------+--------------+
    13. SELECT 4 rows in set (... sec)

    Schema

    routine_name

    Name of the routine (might be duplicated in case of overloading)

    routine_type

    Type of the routine. Can be FUNCTION, ANALYZER, CHAR_FILTER, TOKEN_FILTER or TOKEN_FILTER.

    routine_schema

    The schema where the routine was defined. If it doesn’t apply, then NULL.

    routine_body

    The language used for the routine implementation. If it doesn’t apply, then NULL.

    data_type

    The return type of the function. If it doesn’t apply, then NULL.

    is_deterministic

    If the routine is deterministic then True, else False (NULL if it doesn’t apply).

    routine_definition

    The function definition (NULL if it doesn’t apply).

    specific_name

    Used to uniquely identify the function in a schema, even if the function is overloaded. Currently the specific name contains the types of the function arguments. As the format might change in the future, it should be only used to compare it to other instances of specific_name.

    schemata

    The schemata table lists all existing schemas. Thes blob, information_schema, and sys schemas are always available. The doc schema is available after the first user table is created.

    1. cr> select schema_name from information_schema.schemata order by schema_name;
    2. +--------------------+
    3. | schema_name |
    4. +--------------------+
    5. | blob |
    6. | doc |
    7. | information_schema |
    8. | pg_catalog |
    9. | sys |
    10. +--------------------+
    11. SELECT 5 rows in set (... sec)

    sql_features

    The sql_features table outlines supported and unsupported SQL features of CrateDB based to the current SQL standard (see ):

    1. cr> select feature_name, is_supported, sub_feature_id, sub_feature_name
    2. ... from information_schema.sql_features
    3. ... where feature_id='F501';
    4. +--------------------------------+--------------+----------------+--------------------+
    5. | feature_name | is_supported | sub_feature_id | sub_feature_name |
    6. +--------------------------------+--------------+----------------+--------------------+
    7. | Features and conformance views | FALSE | | |
    8. | Features and conformance views | TRUE | 1 | SQL_FEATURES view |
    9. | Features and conformance views | FALSE | 2 | SQL_SIZING view |
    10. | Features and conformance views | FALSE | 3 | SQL_LANGUAGES view |
    11. +--------------------------------+--------------+----------------+--------------------+
    12. SELECT 4 rows in set (... sec)

    Name

    Data Type

    Nullable

    feature_id

    TEXT

    NO

    feature_name

    TEXT

    NO

    sub_feature_id

    TEXT

    NO

    sub_feature_name

    TEXT

    NO

    is_supported

    TEXT

    NO

    is_verified_by

    TEXT

    YES

    comments

    TEXT

    YES

    feature_id

    Identifier of the feature

    feature_name

    Descriptive name of the feature by the Standard

    sub_feature_id

    Identifier of the subfeature; If it has zero-length, this is a feature

    sub_feature_name

    Descriptive name of the subfeature by the Standard; If it has zero-length, this is a feature

    is_supported

    YES if the feature is fully supported by the current version of CrateDB, NO if not

    is_verified_by

    Identifies the conformance test used to verify the claim;

    Always NULL since the CrateDB development group does not perform formal testing of feature conformance

    comments

    Either NULL or shows a comment about the supported status of the feature

    The character_sets table identifies the character sets available in the current database.

    In CrateDB there is always a single entry listing UTF8:

    1. cr> SELECT character_set_name, character_repertoire FROM information_schema.character_sets;
    2. +--------------------+----------------------+
    3. | character_set_name | character_repertoire |
    4. +--------------------+----------------------+
    5. | UTF8 | UCS |
    6. SELECT 1 row in set (... sec)