Writing data to Yandex Object Storage
In Yandex Query, you can use connections or bindings to write data to Yandex Object Storage buckets.
Query example for writing JSON data via a binding:
INSERT INTO `my_binding`
SELECT
"value" AS value, "name" AS name
FROM
$data;
For a list of supported data formats and compression algorithms, see Supported write formats.
Writing data via a connection
Writing via connections is a convenient option for prototyping and initial setup. To write data to a bucket, create a connection to Object Storage and use the following SQL statement:
INSERT INTO <connection>.<path>
WITH
(
format='<data_format>',
compression='<compression_format>'
)
SELECT
<expression>
FROM
<query>
Where:
<connection>: Object Storage connection name.<path>: Target path within the bucket.<data_format>: Data format.<compression_format>: Data compression algorithm.<statement>: Statement defining the data.<query>: Query source data query.
Example
Query example for writing data to Object Storage via connections:
INSERT INTO `connection`.`test/`
WITH
(
format='csv_with_names'
)
SELECT
"value" AS value, "name" AS name
Where:
connection: Object Storage connection name.test/: Target path within the bucket.
Writing data via data bindings
If you need to write data regularly, you can use bindings to avoid specifying all data operation details in each query. To write data to a bucket, create a binding in Object Storage and then use the following SQL statement:
INSERT INTO `<binding>`
SELECT
<expression>
FROM
<query>
Where:
<binding>: Object Storage data binding name.<statement>: Statement defining the data.<query>: Query source data query.
Example
Query example for writing data to Object Storage using a data binding:
INSERT INTO `test`
SELECT
"value" AS value, "name" AS name
Where:
test: Object Storage data binding name.
Supported write formats
The service currently supports the following formats for writing data:
| Data format | Name in Query |
|---|---|
| CSV |
csv_with_names |
| Parquet |
parquet |
Query supports the following compression algorithms for writing data:
| Compression format | Name in Query |
|---|---|
| Gzip |
gzip |
| Zstd |
zstd |
| LZ4 |
lz4 |
| Brotli |
brotli |
| Bzip2 |
bzip2 |
| Xz |
xz |
While the parquet format supports built-in compression algorithms, Query also enables you to write parquet data using these:
| Compression format | Name in Query |
|---|---|
| Snappy |
None (used by default) |