---
metadata:
  - name: generator
    content: Diplodoc Platform v5.52.0
alternate:
  - https://ydb.tech/docs/en/concepts/query_execution/federated_query/import_and_export.md?version=v26.1
  - https://ydb.tech/docs/ru/concepts/query_execution/federated_query/import_and_export.md?version=v26.1
  - href: en/concepts/query_execution/federated_query/import_and_export.md
    type: text/markdown
    title: Markdown version
  - href: ../../../llms.txt
    type: text/markdown
    title: llms.txt
sourcePath: en/core/concepts/query_execution/federated_query/import_and_export.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# Importing and exporting data with federated queries

{% note info %}

When importing or exporting data to or from S3 in Parquet format, take into account the [YQL and Apache Arrow type mapping](https://ydb.tech/docs/en/concepts/query_execution/federated_query/s3/arrow_types_mapping.md?version=v26.1).

{% endnote %}

## Importing data {#import}

Federated queries let you import data from connected external sources into YDB tables. To import data, use a read query from an [external data source](https://ydb.tech/docs/en/concepts/datamodel/external_data_source.md?version=v26.1) or [external table](https://ydb.tech/docs/en/concepts/datamodel/external_table.md?version=v26.1) and write into a YDB table.

For column-oriented tables, massively parallel import from an external source is supported when using `UPSERT` and `INSERT`: several worker threads read data from the external source in parallel and write into the table. For row-oriented tables, this functionality is under development.

|Operation|Writes to [row-oriented tables](../../datamodel/table.md#row-oriented-tables)|Writes to [column-oriented tables](../../datamodel/table.md#column-oriented-tables)|
|--------|-----------------|------------------|
|[UPSERT](../../../yql/reference/syntax/upsert_into.md)|single-threaded|parallel|
|[REPLACE](../../../yql/reference/syntax/replace_into.md)|single-threaded|parallel|
|[INSERT](../../../yql/reference/syntax/insert_into.md)|single-threaded|parallel|

{% note tip %}

The recommended import options using federated queries are `UPSERT` and `REPLACE` — the import path is heavily optimized for them.

{% endnote %}

Example: import data from a PostgreSQL table into a YDB table:

```yql
UPSERT INTO target_table
SELECT * FROM postgresql_datasource.source_table
```

For more on creating external data sources and external tables, and on read queries, see:

- [ClickHouse](https://ydb.tech/docs/en/concepts/query_execution/federated_query/clickhouse.md?version=v26.1#query)
- [Greenplum](https://ydb.tech/docs/en/concepts/query_execution/federated_query/greenplum.md?version=v26.1#query)
- [Microsoft SQL Server](https://ydb.tech/docs/en/concepts/query_execution/federated_query/ms_sql_server.md?version=v26.1#query)
- [MySQL](https://ydb.tech/docs/en/concepts/query_execution/federated_query/mysql.md?version=v26.1#query)
- [PostgreSQL](https://ydb.tech/docs/en/concepts/query_execution/federated_query/postgresql.md?version=v26.1#query)
- [S3](https://ydb.tech/docs/en/concepts/query_execution/federated_query/s3/external_table.md?version=v26.1)
- [YDB](https://ydb.tech/docs/en/concepts/query_execution/federated_query/ydb.md?version=v26.1#query)

## Exporting data {#export}

Currently, exporting data with federated queries is supported only for S3-compatible storage; see [Exporting data to S3 object storage](https://ydb.tech/docs/en/concepts/query_execution/federated_query/s3/write_data.md?version=v26.1#export-to-s3).
