Attach a table or Dictionary.
Syntax
ATTACH TABLE|DICTIONARY|DATABASE [IF NOT EXISTS] [db.]name
This query does not create Data on storage. Instead, it assumes the Data is already in the appropriate location and only adds the information of the specified table, Dictionary, or Database to the server. After executing the ATTACH query, the server will recognize the existence of the table, Dictionary, or Database.
If the table was previously detached (DETACH query), meaning its structure is already known, the abbreviated form can be used without defining the structure.
Syntax
ATTACH TABLE [IF NOT EXISTS] [db.]name
This query is used when starting the server. The server stores the table's metadata as a file containing the ATTACH query and runs these queries at startup (except for certain system tables, which are explicitly created on the server).
If the table is permanently detached, it will not be reattached at server startup, so the ATTACH query must be used explicitly.
This query creates a new table with the provided structure and attaches table Data from the directory provided in user_files.
Syntax
ATTACH TABLE name FROM 'path/to/data/' (col1 Type1, ...)
Example
DROP TABLE IF EXISTS test; INSERT INTO TABLE FUNCTION file('01188_attach/test/data.TSV', 'TSV', 's String, n UInt8') VALUES ('test', 42); ATTACH TABLE test FROM '01188_attach/test' (s String, n UInt8) ENGINE = File(TSV); SELECT * FROM test; ┌─s────┬──n─┐ │ test │ 42 │ └──────┴────┘
This query creates a new table with the provided structure and attaches Data from the table with the specified UUID. This feature is supported by the Atomic Database engine.
Syntax
ATTACH TABLE name UUID '<uuid>' (col1 Type1, ...)
Attach a previously detached Dictionary.
Syntax
ATTACH DICTIONARY [IF NOT EXISTS] [db.]name
Attach a previously detached Database.
Syntax
ATTACH DATABASE [IF NOT EXISTS] name [ENGINE=<database engine>]