Writing Data to S3 Buckets (Yandex Object Storage)
In YDB, you can use external connections or external tables to write data to the Yandex Object Storage bucket.
Writing Data via External Connection
Using connections for data writing is convenient for prototyping and initial setup. The SQL expression demonstrates writing data directly to an external data source.
INSERT INTO `connection`.`test/`
WITH
(
FORMAT = "csv_with_names"
)
SELECT
"value" AS value, "name" AS name
The data will be written to the specified path. In this mode, the resulting files will not be partitioned. If you need to partition the resulting files, use writing via external tables. The files created during the writing process are assigned random names.
When working with external connections, only read (SELECT) and insert (INSERT) operations are possible; other types of operations are not supported.
Writing Data via External Tables
If you need to write data regularly, doing this using external tables is convenient. In this case, there is no need to specify all the details of working with this data in each query. To write data to the bucket, create an external table in S3 (Yandex Object Storage) and use the usual SQL INSERT INTO statement:
INSERT INTO `test`
SELECT
"value" AS value, "name" AS name
Exporting data to S3 object storage
YDB supports exporting table data to S3 using an external data source.
To export, use a write query via external data source and specify the format of the exported files:
INSERT INTO external_source.`test/`
WITH
(
FORMAT = "parquet"
)
SELECT
*
FROM table
You can export both regular YDB tables and any external tables.
Tip
The recommended export format is parquet; import and export paths are optimized for it.
To export all tables under a given directory in the data schema, plus metadata about tables, directories, and table indexes, to S3-compatible storage, use the YDB CLI. For details, see Exporting data to S3-compatible storage.