---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://ydb.tech/docs/en/concepts/query_execution/federated_query/import_and_export.md?version=main
  - https://ydb.tech/docs/ru/concepts/query_execution/federated_query/import_and_export.md?version=main
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

# Import and export data using federated queries

{% note info %}

When importing/exporting data from/to S3 in Parquet format, you must consider the [mapping of YQL and Apache Arrow types](https://ydb.tech/docs/en/concepts/query_execution/federated_query/s3/arrow_types_mapping.md?version=main).

{% endnote %}

## Data import {#import}

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

For columnar tables, massively parallel import from an external source is supported when using UPSERT and INSERT statements — multiple worker threads read data from the external source in parallel and write to the table. For row-based tables, this functionality is under development.

| Operation | Write to [row-based tables](../../datamodel/table.md#row-oriented-tables) | Write to [columnar 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 the `UPSERT` and `REPLACE` operations — the data import scenario is significantly optimized for them.

{% endnote %}

Example of importing data from a PostgreSQL table into a YDB table:


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


For more details on creating external data sources and external tables, as well as reading data from them, see the articles:

<!-- source: en/concepts/query_execution/federated_query/_includes/supported_eds.md -->
- [S3](https://ydb.tech/docs/en/concepts/query_execution/federated_query/s3/external_table.md?version=main)
<!-- endsource: en/concepts/query_execution/federated_query/_includes/supported_eds.md -->

{% cut "Experimental data sources" %}

<!-- source: en/concepts/query_execution/federated_query/_includes/experimental_eds.md -->
- [ClickHouse](https://ydb.tech/docs/en/concepts/query_execution/federated_query/clickhouse.md?version=main)
- [Greenplum](https://ydb.tech/docs/en/concepts/query_execution/federated_query/greenplum.md?version=main)
- [Microsoft SQL Server](https://ydb.tech/docs/en/concepts/query_execution/federated_query/ms_sql_server.md?version=main)
- [MySQL](https://ydb.tech/docs/en/concepts/query_execution/federated_query/mysql.md?version=main)
- [PostgreSQL](https://ydb.tech/docs/en/concepts/query_execution/federated_query/postgresql.md?version=main)
- [YDB (federated queries between YDB databases)](https://ydb.tech/docs/en/concepts/query_execution/federated_query/ydb.md?version=main)
<!-- endsource: en/concepts/query_execution/federated_query/_includes/experimental_eds.md -->

{% endcut %}

## Data export {#export}

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