---
metadata:
  - name: generator
    content: Diplodoc Platform v5.50.6
alternate:
  - https://ydb.tech/docs/en/yql/reference/syntax/replace_into.md
  - https://ydb.tech/docs/ru/yql/reference/syntax/replace_into.md
sourcePath: en/core/yql/reference/syntax/replace_into.md
---
> **Documentation Index:** Fetch the complete configuration index at https://ydb.tech/docs/en/llms.txt

# REPLACE INTO

<!-- source: en/_includes/limitation-column-row-in-read-only-tx-warn.md -->
{% note warning %}

<!-- source: en/_includes/limitation-column-row-in-read-only-tx.md -->
Currently, mixing [column-oriented tables](https://ydb.tech/docs/en/concepts/glossary.md#column-oriented-table) and [row-oriented tables](https://ydb.tech/docs/en/concepts/glossary.md#row-oriented-table) in a single transaction is supported only if the transaction performs read operations; no writes are allowed. Support for read-write transactions involving both table types is under development.

If a write transaction includes both types of tables, it fails with the following error: `Write transactions that use both row-oriented and column-oriented tables are disabled at current time`.
<!-- endsource: en/_includes/limitation-column-row-in-read-only-tx.md -->

{% endnote %}
<!-- endsource: en/_includes/limitation-column-row-in-read-only-tx-warn.md -->

Saves data to a table, overwriting the rows based on the primary key. If the given primary key is missing, a new row is added to the table. If the given `PRIMARY_KEY` exists, the row is overwritten. The values of columns not involved in the operation are replaced by their default values.

{% note info %}

Unlike [`INSERT INTO`](https://ydb.tech/docs/en/yql/reference/syntax/insert_into.md) and [`UPDATE`](https://ydb.tech/docs/en/yql/reference/syntax/update.md), the queries [`UPSERT INTO`](https://ydb.tech/docs/en/yql/reference/syntax/upsert_into.md) and `REPLACE INTO` don't need to pre-fetch the data, hence they run faster.

{% endnote %}

## Examples

* Setting values for `REPLACE INTO` using `VALUES`.

  ```yql
  REPLACE INTO my_table (Key1, Key2, Value2) VALUES
      (1u, "One", 101),
      (2u, "Two", 102);
  COMMIT;
  ```

* Fetching values for `REPLACE INTO` using a `SELECT`.

  ```yql
  REPLACE INTO my_table
  SELECT Key AS Key1, "Empty" AS Key2, Value AS Value1
  FROM my_table1;
  COMMIT;
  ```

