Overview
TheREPLACE statement allows you to update a table atomically.
This statement is supported for the
Atomic and Replicated database engines,
which are the default database engines for ClickHouse and ClickHouse Cloud respectively.SELECT statement that does not retrieve unwanted data,
then drop the old table and rename the new one.
This approach is demonstrated in the example below:
REPLACE (given you are using the default database engines) to achieve the same result:
Syntax
All syntax forms for the
CREATE statement also work for this statement. Invoking REPLACE for a non-existent table will cause an error.Examples
- Local
- Cloud
Consider the following table:We can use the Or we can use the
REPLACE statement to clear all the data:REPLACE statement to change the table structure: