File

    Usage examples:

    • Data export from ClickHouse to file.
    • Convert data from one format to another.

    The parameter specifies one of the available file formats. To perform
    SELECT queries, the format must be supported for input, and to perform
    INSERT queries — for output. The available formats are listed in the
    Formats section.

    ClickHouse does not allow to specify filesystem path forFile. It will use folder defined by setting in server configuration.

    You may manually create this subfolder and file in server filesystem and then ATTACH it to table information with matching name, so you can query data from that file.

    Warning

    Be careful with this functionality, because ClickHouse does not keep track of external changes to such files. The result of simultaneous writes via ClickHouse and outside of ClickHouse is undefined.

    1. Set up the file_engine_table table:

    By default ClickHouse will create folder /var/lib/clickhouse/data/default/file_engine_table.

    2. Manually create /var/lib/clickhouse/data/default/file_engine_table/data.TabSeparated containing:

    1. SELECT * FROM file_engine_table

    In File engine accepts file path in addition to Format. Default input/output streams can be specified using numeric or human-readable names like 0 or stdin, or stdout.
    Example:

    1. $ echo -e "1,2\n3,4" | clickhouse-local -q "CREATE TABLE table (a Int64, b Int64) ENGINE = File(CSV, stdin); SELECT a, b FROM table; DROP TABLE table"
    • Multiple SELECT queries can be performed concurrently, but INSERT queries will wait each other.
    • Supported creating new file by INSERT query.
    • Not supported:
      • SELECT ... SAMPLE
      • Indices
      • Replication