Replace Tables Atomically
VeloDB Cloud supports atomic replacement between two OLAP tables. A single ALTER TABLE statement performs a table-name swap or a full-table replacement, so newly planned queries resolve either the old or the replacement table. Load and validate the new data before switching names.
Choose a replacement strategy
When a workload needs to rewrite all data in a table without exposing an intermediate "empty data" state, use atomic table replacement.
| Scenario | Recommended approach |
|---|---|
| Full-table rewrite (such as offline full backfill) | Use CREATE TABLE LIKE to create a new table, load the new data, and atomically replace the old table |
| Replace only a specific partition | See Temporary Partition |
| Keep the old table for rollback | Use swap = true. The old table data is moved under the new table name |
| No need to keep the old table after replacement | Use swap = false. The old table leaves the active catalog |
Replace a table
Take "replacing the old table tbl1 with new data" as an example. The standard procedure is:
-
Create a new table based on the schema of the old table:
CREATE TABLE tbl2 LIKE tbl1; -
Load the new data into the new table
tbl2. -
Run the atomic replacement:
ALTER TABLE tbl1 REPLACE WITH TABLE tbl2PROPERTIES('swap' = 'true'); -
Confirm the result based on the
swapparameter (see below for details).
Write the replacement statement
ALTER TABLE [db.]tbl1 REPLACE WITH TABLE tbl2
[PROPERTIES('swap' = 'true')] [FORCE];
Meaning: replace table tbl1 with table tbl2. The swap parameter controls how the old table is handled after replacement.
Choose how to retain the old table
| swap value | Data of tbl1 after replacement | State of tbl2 after replacement | Typical use |
|---|---|---|---|
true (default) | The original data of tbl2 | Retained, and contains the original data of tbl1 (the two tables are swapped) | Keep the old data for rollback or comparison |
false | The original data of tbl2 | The name tbl2 is removed. The old tbl1 is recycled unless FORCE is used | Discard the old active table |
Understand the metadata switch
Atomic replacement merges several DDL steps into one atomic operation. The catalog exposes the name change as one metadata switch.
-
When
swap = true:- Rename table B to table A.
- Rename table A to table B.
-
When
swap = false:- Drop table A.
- Rename table B to table A.
Because these steps run as an atomic transaction at the metadata layer, external queries do not observe any intermediate state.
Check replacement constraints
- Replacement is supported only between two OLAP tables. Other table types are not supported.
- The system does not validate that the two tables have identical schemas. You must ensure schema compatibility yourself.
- When
swap = false, the old table is recycled unlessFORCEis specified. Recovery depends on retention and permissions. Recover it under a different name to avoid colliding with the replacement table. Useswap = truewhen you need an immediate rollback path. - Check that the account has the required privileges for the replacement. Existing grants on a table name continue to apply to that name. Recheck access and dependent queries after replacement.
Resolve common questions
Coordinate running queries
Replacement switches metadata atomically, so new queries do not see an intermediate missing-table state. Coordinate concurrent writes and validate long-running workloads before production replacement. Atomic metadata replacement alone is not a guarantee that every in-flight query succeeds.
Validate compatible schemas
Yes. The system does not validate schema consistency, but you should keep schemas compatible. Otherwise, downstream queries and applications may fail because of column-name or type changes.
Retain a recovery path
With swap = true, the original data remains under tbl2, and you can swap the tables again. With swap = false, the old table is eligible for recycle-bin recovery unless FORCE was used. See RECOVER.
Replace individual partitions
Yes. Use the Temporary Partition feature for partition-level atomic overwrite.
Explore related references
- Temporary Partition: partition-level atomic overwrite
CREATE TABLE LIKE: quickly create a new table based on an existing table schema