Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does CREATE OR REPLACE statement affect time travel in snowflake?

If I create a table in snowflake and then create another one with the same name using CREATE OR REPLACE statement, I am not able to access the content of the first table using time travel.

For example, if I run this code

CREATE TABLE "MY_DB"."MY_SCHEMA"."MY_TABLE" (COL1 VARCHAR, COL2 NUMBER);   
INSERT INTO "MY_DB"."MY_SCHEMA"."MY_TABLE" VALUES ('A',1);

... and then in five minutes run this chunk of code

CREATE OR REPLACE TABLE "MY_DB"."MY_SCHEMA"."MY_TABLE" (COL1 VARCHAR, COL2 NUMBER);
INSERT INTO "MY_DB"."MY_SCHEMA"."MY_TABLE" VALUES ('B',2);
SELECT * FROM "MY_DB"."MY_SCHEMA"."MY_TABLE"
UNION
SELECT * FROM "MY_DB"."MY_SCHEMA"."MY_TABLE" AT (offset => -60*1)

The query only returns the values from the second table. Is this behavior expected? I tried to google this or find clarification in snowflake documentation without any luck...

Thank you

like image 480
Andrey S Avatar asked Dec 14 '22 07:12

Andrey S


1 Answers

You can also restore the old table by using time travel at the schema level to the time before you ran Create or Replace Table:

create schema "MY_DB"."MY_SCHEMA_RESTORED" clone "MY_DB"."MY_SCHEMA" AT (offset => -60*1)
like image 156
peterb Avatar answered Jan 13 '23 12:01

peterb