You need to enable JavaScript to run this app.
ByteHouse Cloud Data Warehouse Version

ByteHouse Cloud Data Warehouse Version

Copy page
Download PDF
DDL
ATTACH statement (ATTACH)
Copy page
Download PDF
ATTACH statement (ATTACH)

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.

Attach an existing table

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.

Create a new table and attach Data

Use the specified table Data path

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 │ 
└──────┴────┘

Use the specified table UUID

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 an existing Dictionary

Attach a previously detached Dictionary.
Syntax

ATTACH DICTIONARY [IF NOT EXISTS] [db.]name

Attach an existing Database

Attach a previously detached Database.
Syntax

ATTACH DATABASE [IF NOT EXISTS] name [ENGINE=<database engine>]
Last updated: 2026.03.31 10:31:07