Skip to main content
Provides a table-like interface to SELECT and INSERT data from Google Cloud Storage. Requires the Storage Object User IAM role. This is an alias of the s3 table function. If you have multiple replicas in your cluster, you can use the s3Cluster function (which works with GCS) instead to parallelize inserts.

Syntax

GCSThe GCS Table Function integrates with Google Cloud Storage by using the GCS XML API and HMAC keys. See the Google interoperability docs for more details about the endpoint and HMAC.

Arguments

GCSThe GCS path is in this format as the endpoint for the Google XML API is different than the JSON API:
and not https://storage.cloud.google.com.
Arguments can also be passed using named collections. In this case url, format, structure, compression_method work in the same way, and some extra parameters are supported:

Returned value

A table with the specified structure for reading or writing data in the specified file.

Examples

Selecting the first two rows from the GCS file https://storage.googleapis.com/clickhouse_public_datasets/my-test-bucket-768/data.csv.gz. The compression method is detected automatically from the .gz file extension:
The same query as above, but with the gzip compression method specified explicitly instead of relying on autodetection:

Usage

Suppose that we have several files with following URIs on GCS: Count the amount of rows in files ending with numbers from 1 to 3:
Count the total amount of rows in all files in these two directories:
If your listing of files contains number ranges with leading zeros, use the construction with braces for each digit separately or use ?.
Count the total amount of rows in files named file-000.csv, file-001.csv, … , file-999.csv:
Insert data into file test-data.csv.gz:
Insert data into file test-data.csv.gz from existing table:
Glob ** can be used for recursive directory traversal. Consider the below example, it will fetch all files from my-test-bucket-768 directory recursively:
The below get data from all test-data.csv.gz files from any folder inside my-test-bucket directory recursively:
For production use cases it is recommended to use named collections. Here is the example:

Partitioned Write

If you specify PARTITION BY expression when inserting data into GCS table, a separate file is created for each partition value. Splitting the data into separate files helps to improve reading operations efficiency. Examples
  1. Using partition ID in a key creates separate files:
As a result, the data is written into three files: file_x.csv, file_y.csv, and file_z.csv.
  1. Using partition ID in a bucket name creates files in different buckets:
As a result, the data is written into three files in different buckets: my_bucket_1/file.csv, my_bucket_10/file.csv, and my_bucket_20/file.csv.
Last modified on July 1, 2026