In this post we are going to cover zero-copy cloning in Snowflake.
A clone is a second name over data that is already stored. It is not a copy, because nothing is copied. It is not a pointer either, because the two names go their own way the moment either side is written to.
We will start by cloning one small table and build it up step by step, through a clone of the past, a whole schema, and a whole database. Every query below was run on a real Snowflake account, and every result you see is the output it gave back.
Episode 134 of the Snowflake SQL: Zero to Hero series on TechBrothersIT.
- Let's create some sample data
- Let's clone it
- Now let's ask the catalog what the two of them weigh
- Now let's write to one side only
- What happens when we drop the source?
- So what else comes across, and when is that decided?
- Can a transient table be cloned into a permanent one?
- Can we clone the table as it used to be?
- Now let's clone a whole schema
- And did the stage come with it?
- One statement clones a whole database, and moves you into it
- A few more things CLONE will not do
- One last thing: the pattern that matched nothing
- And the cleanup, written for the wreckage
Let's create some sample data
We need a table with something to carry, so that we can see what travels to a clone and what does not. This one has a NOT NULL, a DEFAULT, a clustering key and a comment.
-- Sample data for this post.
-- A table with a few things on it worth watching: a NOT NULL, a DEFAULT,
-- a clustering key and a comment.
USE DATABASE DEMO_DB;
USE SCHEMA PUBLIC;
CREATE OR REPLACE TABLE SALES_T134 (
SALE_ID INT NOT NULL,
REGION VARCHAR(10) DEFAULT 'unknown',
AMOUNT NUMBER(10,2)
)
CLUSTER BY (REGION)
COMMENT = 'the source table for episode 134';
INSERT INTO SALES_T134 (SALE_ID, REGION, AMOUNT)
VALUES (1, 'north', 100.00), (2, 'south', 250.50),
(3, 'east', 75.25), (4, 'west', 310.00),
(5, 'north', 45.00), (6, 'south', 88.25);Let's see what is in it.
SELECT COUNT(*) AS ROWS_IN_THE_TABLE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_T134;| ROWS_IN_THE_TABLE | TOTAL_AMOUNT |
|---|---|
| 6 | 869.00 |
Six rows and 869.00. Those are the two numbers to watch for the rest of this post.
Let's clone it
One statement, and no options to get wrong.
CREATE OR REPLACE TABLE SALES_CLONE_T134 CLONE SALES_T134;| status |
|---|
| Table SALES_CLONE_T134 successfully created. |
Now let's ask the clone what it holds.
SELECT COUNT(*) AS ROWS_IN_THE_CLONE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_CLONE_T134;| ROWS_IN_THE_CLONE | TOTAL_AMOUNT |
|---|---|
| 6 | 869.00 |
Six rows and 869.00. The same two numbers.
And the rows themselves, so there is no doubt about it.
SELECT SALE_ID, REGION, AMOUNT
FROM SALES_CLONE_T134
ORDER BY SALE_ID;| SALE_ID | REGION | AMOUNT |
|---|---|---|
| 1 | north | 100.00 |
| 2 | south | 250.50 |
| 3 | east | 75.25 |
| 4 | west | 310.00 |
| 5 | north | 45.00 |
| 6 | south | 88.25 |
That part is not a surprise. The interesting question is what the catalog now thinks it is looking after.
Now let's ask the catalog what the two of them weigh
SHOW TABLES gives us both of them side by side.
SHOW TABLES LIKE '%\\_T134' IN SCHEMA PUBLIC;| created_on | name | database_name | schema_name | kind | comment | cluster_by | rows | bytes | owner | retention_time | automatic_clustering | change_tracking | search_optimization | search_optimization_progress | search_optimization_bytes | is_external | enable_schema_evolution | owner_role_type | is_event | is_hybrid | is_iceberg | is_dynamic | is_immutable | is_interactive | row_timestamp | error_logging |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2026-10-02 08:45:22.951000-07:00 | SALES_CLONE_T134 | DEMO_DB | PUBLIC | TABLE | the source table for episode 134 | LINEAR(REGION) | 6 | 1024 | ACCOUNTADMIN | 1 | OFF | OFF | OFF | NULL | NULL | N | N | ROLE | N | N | N | N | N | N | OFF | OFF |
| 2026-10-02 08:45:21.238000-07:00 | SALES_T134 | DEMO_DB | PUBLIC | TABLE | the source table for episode 134 | LINEAR(REGION) | 6 | 1024 | ACCOUNTADMIN | 1 | ON | OFF | OFF | NULL | NULL | N | N | ROLE | N | N | N | N | N | N | OFF | OFF |
Twenty seven columns, which is a lot to read at once. Start with rows and bytes. Six rows and 1024 bytes, for each of them.
The same 1024 bytes, twice, for data that is stored once. Zero-copy is real, and the catalog bills it to both names.
Now read down the column headings. There is no column that says this one is a clone. A clone is indistinguishable here from a table somebody built the long way.
There is one honest difference and it is easy to miss. automatic_clustering is ON for the source and OFF for the clone. The clustering key travelled. The service that acts on it did not.
While that grid is in front of you, have a look at its blank-looking cells. search_optimization_progress and search_optimization_bytes are real NULLs, and the grid prints them as NULL. SHOW output also uses empty strings for missing values, and the grid marks those as empty instead. Two different things that both look like nothing.
The catalog view answers the same question in fewer columns.
SELECT TABLE_NAME,
TABLE_TYPE,
IS_TRANSIENT,
ROW_COUNT,
BYTES,
RETENTION_TIME,
CLUSTERING_KEY,
COMMENT
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC'
AND ENDSWITH(TABLE_NAME, '_T134')
ORDER BY TABLE_NAME;| TABLE_NAME | TABLE_TYPE | IS_TRANSIENT | ROW_COUNT | BYTES | RETENTION_TIME | CLUSTERING_KEY | COMMENT |
|---|---|---|---|---|---|---|---|
| SALES_CLONE_T134 | BASE TABLE | NO | 6 | 1024 | 1 | LINEAR(REGION) | the source table for episode 134 |
| SALES_T134 | BASE TABLE | NO | 6 | 1024 | 1 | LINEAR(REGION) | the source table for episode 134 |
Same row count, same byte count, same clustering key, same comment, and neither of them is transient. The comment came across with the clone, which is worth noticing: the comment says the source table for episode 134 on a table that is not the source.
And if you want to see exactly what came with it, ask for the DDL of each one.
SELECT GET_DDL('TABLE', 'SALES_T134') AS THE_SOURCE_DDL;| THE_SOURCE_DDL |
|---|
| create or replace TABLE SALES_T134 cluster by (REGION)( SALE_ID NUMBER(38,0) NOT NULL, REGION VARCHAR(10) DEFAULT 'unknown', AMOUNT NUMBER(10,2) )COMMENT='the source table for episode 134' ; |
SELECT GET_DDL('TABLE', 'SALES_CLONE_T134') AS THE_CLONE_DDL;| THE_CLONE_DDL |
|---|
| create or replace TABLE SALES_CLONE_T134 cluster by (REGION)( SALE_ID NUMBER(38,0) NOT NULL, REGION VARCHAR(10) DEFAULT 'unknown', AMOUNT NUMBER(10,2) )COMMENT='the source table for episode 134' ; |
Two identical definitions apart from the name. The NOT NULL, the DEFAULT, the cluster by and the comment are all in the clone's own DDL.
Now let's write to one side only
Before we change anything, let's keep hold of this moment. We are going to want to come back to it later.
SET QID_SIX = LAST_QUERY_ID();| status |
|---|
| Statement executed successfully. |
That variable now holds the id of the statement that ran just before it. The grid that prints the id itself is left off this page, because a query id belongs to one account's own history and there is nothing to learn from reading it.
Now a row into the clone, and nothing into the source.
INSERT INTO SALES_CLONE_T134 (SALE_ID, REGION, AMOUNT)
VALUES (7, 'east', 500.00);| number of rows inserted |
|---|
| 1 |
SELECT COUNT(*) AS ROWS_IN_THE_CLONE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_CLONE_T134;| ROWS_IN_THE_CLONE | TOTAL_AMOUNT |
|---|---|
| 7 | 1369.00 |
SELECT COUNT(*) AS ROWS_IN_THE_SOURCE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_T134;| ROWS_IN_THE_SOURCE | TOTAL_AMOUNT |
|---|---|
| 6 | 869.00 |
The clone is up to seven rows and 1369.00. The source is still six rows and 869.00. It did not notice.
Now the other direction. Let's change the source instead.
UPDATE SALES_T134 SET AMOUNT = 0 WHERE REGION = 'south';| number of rows updated | number of multi-joined rows updated |
|---|---|
| 2 | 0 |
SELECT COUNT(*) AS ROWS_IN_THE_SOURCE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_T134;| ROWS_IN_THE_SOURCE | TOTAL_AMOUNT |
|---|---|
| 6 | 530.25 |
SELECT COUNT(*) AS ROWS_IN_THE_CLONE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_CLONE_T134;| ROWS_IN_THE_CLONE | TOTAL_AMOUNT |
|---|---|
| 7 | 1369.00 |
Two rows updated, so the source is six rows and 530.25 now. The clone is still seven rows and 1369.00.
Let's put them next to each other and label every row, because that is the grid you actually want to see.
SELECT COALESCE(s.SALE_ID, c.SALE_ID) AS SALE_ID,
s.AMOUNT AS IN_THE_SOURCE,
c.AMOUNT AS IN_THE_CLONE,
CASE WHEN s.SALE_ID IS NULL THEN 'CLONE ONLY'
WHEN c.SALE_ID IS NULL THEN 'SOURCE ONLY'
WHEN s.AMOUNT <> c.AMOUNT THEN 'DIFFERENT'
ELSE 'same'
END AS VERDICT
FROM SALES_T134 s
FULL OUTER JOIN SALES_CLONE_T134 c ON s.SALE_ID = c.SALE_ID
ORDER BY SALE_ID;| SALE_ID | IN_THE_SOURCE | IN_THE_CLONE | VERDICT |
|---|---|---|---|
| 1 | 100.00 | 100.00 | same |
| 2 | 0.00 | 250.50 | DIFFERENT |
| 3 | 75.25 | 75.25 | same |
| 4 | 310.00 | 310.00 | same |
| 5 | 45.00 | 45.00 | same |
| 6 | 0.00 | 88.25 | DIFFERENT |
| 7 | NULL | 500.00 | CLONE ONLY |
Sale 2 and sale 6 are different, because those are the two south rows we zeroed in the source. Sale 7 is in the clone only. Everything else is the same on both sides.
What happens when we drop the source?
This is the part a copy and a pointer would answer differently, so it is the part worth doing carefully.
First let's make the two sides easy to tell apart. Two rows out of the source.
DELETE FROM SALES_T134 WHERE SALE_ID IN (5, 6);| number of rows deleted |
|---|
| 2 |
SELECT COUNT(*) AS ROWS_IN_THE_SOURCE FROM SALES_T134;| ROWS_IN_THE_SOURCE |
|---|
| 4 |
SELECT COUNT(*) AS ROWS_IN_THE_CLONE FROM SALES_CLONE_T134;| ROWS_IN_THE_CLONE |
|---|
| 7 |
Four rows on one side and seven on the other. Now let's drop the source entirely.
DROP TABLE SALES_T134;| status |
|---|
| SALES_T134 successfully dropped. |
And select from it, to be sure it really is gone.
SELECT COUNT(*) AS ROWS_IN_THE_SOURCE FROM SALES_T134;002003 (42S02): SQL compilation error: Object 'SALES_T134' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on TABLE SALES_T134.
002003, does not exist or not authorized. The source is gone. Now let's read the clone.
SELECT COUNT(*) AS ROWS_IN_THE_CLONE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_CLONE_T134;| ROWS_IN_THE_CLONE | TOTAL_AMOUNT |
|---|---|
| 7 | 1369.00 |
Seven rows and 1369.00. It is still there.
The clone outlives the table it was made from, because the storage underneath was never the source's to own.
And the source is only dropped, not destroyed, so we can have it back.
UNDROP TABLE SALES_T134;| status |
|---|
| Table SALES_T134 successfully restored. |
SELECT COUNT(*) AS ROWS_IN_THE_SOURCE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_T134;| ROWS_IN_THE_SOURCE | TOTAL_AMOUNT |
|---|---|
| 4 | 485.25 |
Four rows and 485.25, which is where we left it. Both of them exist again, side by side.
So what else comes across, and when is that decided?
Retention is a good one to ask about, because it is a setting rather than data. Let's raise it on the source and then clone the source a second time.
ALTER TABLE SALES_T134 SET DATA_RETENTION_TIME_IN_DAYS = 3;| status |
|---|
| Statement executed successfully. |
CREATE OR REPLACE TABLE SALES_CLONE2_T134 CLONE SALES_T134;| status |
|---|
| Table SALES_CLONE2_T134 successfully created. |
So now there are three tables. The source, a clone made before the change, and a clone made after it.
SELECT TABLE_NAME, RETENTION_TIME, CLUSTERING_KEY, COMMENT
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC'
AND TABLE_NAME IN ('SALES_T134', 'SALES_CLONE_T134', 'SALES_CLONE2_T134')
ORDER BY TABLE_NAME;| TABLE_NAME | RETENTION_TIME | CLUSTERING_KEY | COMMENT |
|---|---|---|---|
| SALES_CLONE2_T134 | 3 | LINEAR(REGION) | the source table for episode 134 |
| SALES_CLONE_T134 | 1 | LINEAR(REGION) | the source table for episode 134 |
| SALES_T134 | 3 | LINEAR(REGION) | the source table for episode 134 |
Three answers. The source says 3. The clone made after the change says 3. The first clone, made before it, still says 1.
So retention is copied at the moment you clone, and then the two settings go their own way. Changing the source later does not reach a clone that already exists.
Can a transient table be cloned into a permanent one?
Let's make a transient table and clone it without saying the word transient.
CREATE OR REPLACE TRANSIENT TABLE TRANS_T134 (
SALE_ID INT,
AMOUNT NUMBER(10,2)
);| status |
|---|
| Table TRANS_T134 successfully created. |
INSERT INTO TRANS_T134 (SALE_ID, AMOUNT) VALUES (1, 10.00), (2, 20.00);| number of rows inserted |
|---|
| 2 |
CREATE OR REPLACE TABLE TRANSCLONE_T134 CLONE TRANS_T134;002120 (0A000): SQL compilation error: Transient object cannot be cloned to a permanent object.
002120, Transient object cannot be cloned to a permanent object. Refused.
Let's ask the catalog which of those two tables exists.
SELECT TABLE_NAME, TABLE_TYPE, IS_TRANSIENT, RETENTION_TIME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC'
AND TABLE_NAME IN ('TRANS_T134', 'TRANSCLONE_T134')
ORDER BY TABLE_NAME;| TABLE_NAME | TABLE_TYPE | IS_TRANSIENT | RETENTION_TIME |
|---|---|---|---|
| TRANS_T134 | BASE TABLE | YES | 1 |
One row. The transient table is there and the clone was never created, which is what a compilation error means.
Now the other direction. A transient clone of a permanent table.
CREATE OR REPLACE TRANSIENT TABLE PERMCLONE_T134 CLONE SALES_T134;| status |
|---|
| Table PERMCLONE_T134 successfully created. |
SELECT TABLE_NAME, TABLE_TYPE, IS_TRANSIENT, RETENTION_TIME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC'
AND TABLE_NAME = 'PERMCLONE_T134';| TABLE_NAME | TABLE_TYPE | IS_TRANSIENT | RETENTION_TIME |
|---|---|---|---|
| PERMCLONE_T134 | BASE TABLE | YES | 1 |
Accepted, and IS_TRANSIENT says YES.
So it is a one-way door. Permanent to transient is fine, and transient to permanent is refused. Which makes sense once you say it out loud: you cannot promise more durability than the data ever had.
Can we clone the table as it used to be?
Yes, and this is the one worth knowing. Remember the statement id we kept earlier, from before the update. Let's clone the source as it was before that statement ran.
CREATE OR REPLACE TABLE PAST_T134 CLONE SALES_T134
BEFORE (STATEMENT => $QID_SIX);| status |
|---|
| Table PAST_T134 successfully created. |
SELECT COUNT(*) AS ROWS_IN_IT,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM PAST_T134;| ROWS_IN_IT | TOTAL_AMOUNT |
|---|---|
| 6 | 869.00 |
Six rows and 869.00. That is the table as it stood before the update and before the delete.
SELECT SALE_ID, REGION, AMOUNT
FROM PAST_T134
ORDER BY SALE_ID;| SALE_ID | REGION | AMOUNT |
|---|---|---|
| 1 | north | 100.00 |
| 2 | south | 250.50 |
| 3 | east | 75.25 |
| 4 | west | 310.00 |
| 5 | north | 45.00 |
| 6 | south | 88.25 |
All six rows, with the two south amounts back at 250.50 and 88.25.
This is not a query against history. It is a real table, built from history, that you can read, join and write to.
An offset works as well, if you want a moment rather than a statement.
CREATE OR REPLACE TABLE PASTOFF_T134 CLONE SALES_T134 AT (OFFSET => -5);| status |
|---|
| Table PASTOFF_T134 successfully created. |
SELECT COUNT(*) AS ROWS_IN_IT,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM PASTOFF_T134;| ROWS_IN_IT | TOTAL_AMOUNT |
|---|---|
| 4 | 485.25 |
Four rows and 485.25, which is a few seconds ago rather than the beginning.
And the two ways of asking for a moment that is not there
First, a moment before the table existed at all.
CREATE OR REPLACE TABLE PASTNEVER_T134 CLONE SALES_T134
BEFORE (STATEMENT => $QID_START);000707 (02000): Time travel data is not available for table SALES_T134. The requested time is either beyond the allowed time travel period or before the object creation time.
000707, time travel data is not available. The message names both reasons at once: either beyond the allowed period, or before the object was created.
And second, a positive offset, which asks for the future.
CREATE OR REPLACE TABLE PASTFUTURE_T134 CLONE SALES_T134 AT (OFFSET => 60);002038 (22000): SQL compilation error: Invalid data type [60] in AT(OFFSET => 60)
002038, Invalid data type [60] in AT(OFFSET => 60). There is nothing wrong with the data type. The number is simply not allowed to be positive, and the message does not say so.
Now let's clone a whole schema
A schema is where cloning stops being simple, because the things inside a schema refer to each other.
So let's build one with two views over the same table. The first names its table plainly. The second spells out the whole path. Their bodies are otherwise identical.
-- A schema with things inside it that refer to each other.
CREATE OR REPLACE SCHEMA CLONEZONE_T134;
CREATE OR REPLACE TABLE CLONEZONE_T134.INSIDE_T134 (
SALE_ID INT,
AMOUNT NUMBER(10,2)
);
INSERT INTO CLONEZONE_T134.INSIDE_T134 (SALE_ID, AMOUNT)
VALUES (1, 100.00), (2, 200.00);
-- The first view names its table plainly.
CREATE OR REPLACE VIEW CLONEZONE_T134.PLAIN_VIEW_T134 AS
SELECT COUNT(*) AS ROWS_IT_CAN_SEE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM INSIDE_T134;
-- The second one spells out the whole path. Same body otherwise.
CREATE OR REPLACE VIEW CLONEZONE_T134.QUALIFIED_VIEW_T134 AS
SELECT COUNT(*) AS ROWS_IT_CAN_SEE,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM DEMO_DB.CLONEZONE_T134.INSIDE_T134;
-- And one more table, cloned across the schema line from PUBLIC.
CREATE OR REPLACE TABLE CLONEZONE_T134.OVER_THERE_T134 CLONE SALES_CLONE_T134;SELECT COUNT(*) AS ROWS_IN_IT,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM CLONEZONE_T134.OVER_THERE_T134;| ROWS_IN_IT | TOTAL_AMOUNT |
|---|---|
| 7 | 1369.00 |
Seven rows and 1369.00, so cloning across a schema line works the same as cloning inside one.
Now let's clone the whole schema in one statement.
CREATE OR REPLACE SCHEMA CLONEZONE_CLONE_T134 CLONE CLONEZONE_T134;| status |
|---|
| Schema CLONEZONE_CLONE_T134 successfully created. |
SELECT TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE, ROW_COUNT
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA IN ('CLONEZONE_T134', 'CLONEZONE_CLONE_T134')
ORDER BY TABLE_SCHEMA, TABLE_NAME;| TABLE_SCHEMA | TABLE_NAME | TABLE_TYPE | ROW_COUNT |
|---|---|---|---|
| CLONEZONE_CLONE_T134 | INSIDE_T134 | BASE TABLE | 2 |
| CLONEZONE_CLONE_T134 | OVER_THERE_T134 | BASE TABLE | 7 |
| CLONEZONE_CLONE_T134 | PLAIN_VIEW_T134 | VIEW | NULL |
| CLONEZONE_CLONE_T134 | QUALIFIED_VIEW_T134 | VIEW | NULL |
| CLONEZONE_T134 | INSIDE_T134 | BASE TABLE | 2 |
| CLONEZONE_T134 | OVER_THERE_T134 | BASE TABLE | 7 |
| CLONEZONE_T134 | PLAIN_VIEW_T134 | VIEW | NULL |
| CLONEZONE_T134 | QUALIFIED_VIEW_T134 | VIEW | NULL |
Eight rows, four on each side. Both tables and both views came across. The views have no ROW_COUNT, and those cells are real NULLs rather than zeroes.
SELECT COUNT(*) AS ROWS_IN_IT,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM CLONEZONE_CLONE_T134.INSIDE_T134;| ROWS_IN_IT | TOTAL_AMOUNT |
|---|---|
| 2 | 300.00 |
Two rows and 300.00, the same as the original.
Now let's change the original only
One row into the original table, and nothing into the clone.
INSERT INTO CLONEZONE_T134.INSIDE_T134 (SALE_ID, AMOUNT) VALUES (3, 300.00);| number of rows inserted |
|---|
| 1 |
SELECT COUNT(*) AS ROWS_IN_THE_ORIGINAL FROM CLONEZONE_T134.INSIDE_T134;| ROWS_IN_THE_ORIGINAL |
|---|
| 3 |
SELECT COUNT(*) AS ROWS_IN_THE_CLONE FROM CLONEZONE_CLONE_T134.INSIDE_T134;| ROWS_IN_THE_CLONE |
|---|
| 2 |
Three rows on one side, two on the other. Now we can ask each view, inside the clone, what it can see.
SELECT ROWS_IT_CAN_SEE, TOTAL_AMOUNT
FROM CLONEZONE_CLONE_T134.PLAIN_VIEW_T134;| ROWS_IT_CAN_SEE | TOTAL_AMOUNT |
|---|---|
| 2 | 300.00 |
Two rows and 300.00. That is its own table, in its own schema. Which is what you would expect.
SELECT ROWS_IT_CAN_SEE, TOTAL_AMOUNT
FROM CLONEZONE_CLONE_T134.QUALIFIED_VIEW_T134;| ROWS_IT_CAN_SEE | TOTAL_AMOUNT |
|---|---|
| 3 | 600.00 |
Three rows and 600.00.
That is the original's number. The qualified view is sitting inside the cloned schema and reading the original table, across the schema line, in a schema it was never cloned into.
And the catalog shows the mechanism rather than an explanation of it.
SELECT TABLE_NAME, VIEW_DEFINITION
FROM INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = 'CLONEZONE_CLONE_T134'
ORDER BY TABLE_NAME;| TABLE_NAME | VIEW_DEFINITION |
|---|---|
| PLAIN_VIEW_T134 | CREATE OR REPLACE VIEW CLONEZONE_CLONE_T134.PLAIN_VIEW_T134 AS SELECT COUNT(*) AS ROWS_IT_CAN_SEE, SUM(AMOUNT) AS TOTAL_AMOUNT FROM INSIDE_T134 |
| QUALIFIED_VIEW_T134 | CREATE OR REPLACE VIEW CLONEZONE_CLONE_T134.QUALIFIED_VIEW_T134 AS SELECT COUNT(*) AS ROWS_IT_CAN_SEE, SUM(AMOUNT) AS TOTAL_AMOUNT FROM DEMO_DB.CLONEZONE_T134.INSIDE_T134 |
Both definitions now say CLONEZONE_CLONE_T134 at the top, because both views really are in the clone. Look at the FROM line of each. One reads FROM INSIDE_T134. The other still reads FROM DEMO_DB.CLONEZONE_T134.INSIDE_T134.
Cloning re-points an unqualified name and leaves a qualified one exactly where it was pointing. So two views with the same body, written two different ways, end up reading two different tables. If you clone a schema to get a safe copy to work in, every fully qualified reference inside it is still aimed at production.
And did the stage come with it?
There was a stage in that schema too, with one file on it. Let's look at what we put there before the clone.
COPY INTO @CLONEZONE_T134.STG_T134/out/
FROM (SELECT SALE_ID, AMOUNT FROM CLONEZONE_T134.INSIDE_T134)
FILE_FORMAT = (TYPE = CSV)
OVERWRITE = TRUE;| rows_unloaded | input_bytes | output_bytes |
|---|---|---|
| 2 | 18 | 33 |
Two rows unloaded, and this grid reports output_bytes of 33.
LIST @CLONEZONE_T134.STG_T134;| name | size | md5 | last_modified |
|---|---|---|---|
| stg_t134/out/data_0_0_0.csv.gz | 48 | a757ad74e4c2ca54c5c9b3430a12a403 | Fri, 2 Oct 2026 15:45:50 GMT |
One file, and this grid reports its size as 48. Those are two different measurements taken by two different statements, so take each number from the grid it came from and do not expect them to agree.
Now let's list the same stage inside the cloned schema.
LIST @CLONEZONE_CLONE_T134.STG_T134;002003 (02000): SQL compilation error: Stage 'DEMO_DB.CLONEZONE_CLONE_T134.STG_T134' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on STAGE DEMO_DB.CLONEZONE_CLONE_T134.STG_T134.
002003, the stage does not exist. The schema cloned, the tables cloned, the views cloned, and the stage did not come at all.
One statement clones a whole database, and moves you into it
Before we clone anything, let's look at where the session is pointing.
SELECT CURRENT_DATABASE() AS THE_DATABASE,
CURRENT_SCHEMA() AS THE_SCHEMA;| THE_DATABASE | THE_SCHEMA |
|---|---|
| DEMO_DB | CLONEZONE_CLONE_T134 |
DEMO_DB, and the schema we created a few sections ago. Creating a schema had already moved the session into it, which is easy not to notice.
Now let's clone the database.
CREATE OR REPLACE DATABASE CLONEDB_T134 CLONE DEMO_DB;| status |
|---|
| Database CLONEDB_T134 successfully created. |
SELECT CURRENT_DATABASE() AS THE_DATABASE,
CURRENT_SCHEMA() AS THE_SCHEMA;| THE_DATABASE | THE_SCHEMA |
|---|---|
| CLONEDB_T134 | PUBLIC |
CLONEDB_T134 and PUBLIC. Creating a database moves your session into it.
Which means an unqualified name now means something else entirely.
SELECT COUNT(*) AS ROWS_AN_UNQUALIFIED_NAME_FINDS,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM SALES_CLONE_T134;| ROWS_AN_UNQUALIFIED_NAME_FINDS | TOTAL_AMOUNT |
|---|---|
| 7 | 1369.00 |
Seven rows and 1369.00, resolved inside the clone. The same statement would have found the same numbers in DEMO_DB on this data, which is exactly why it is dangerous.
So let's put the session back where it belongs before going any further.
USE DATABASE DEMO_DB;| status |
|---|
| Statement executed successfully. |
SELECT CURRENT_DATABASE() AS THE_DATABASE,
CURRENT_SCHEMA() AS THE_SCHEMA;| THE_DATABASE | THE_SCHEMA |
|---|---|
| DEMO_DB | PUBLIC |
Now we can read the clone by name instead of by accident.
SELECT COUNT(*) AS TABLES_IN_DEMO_DB_PUBLIC
FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC';| TABLES_IN_DEMO_DB_PUBLIC |
|---|
| 18 |
SELECT COUNT(*) AS TABLES_IN_THE_CLONED_DB_PUBLIC
FROM CLONEDB_T134.INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC';| TABLES_IN_THE_CLONED_DB_PUBLIC |
|---|
| 18 |
Eighteen tables in PUBLIC on each side.
SELECT SCHEMA_NAME
FROM CLONEDB_T134.INFORMATION_SCHEMA.SCHEMATA
ORDER BY SCHEMA_NAME;| SCHEMA_NAME |
|---|
| CLONEZONE_CLONE_T134 |
| CLONEZONE_T134 |
| INFORMATION_SCHEMA |
| PUBLIC |
Four schemas, including both of the ones we made earlier. The schemas came too.
SELECT COUNT(*) AS ROWS_IN_IT,
SUM(AMOUNT) AS TOTAL_AMOUNT
FROM CLONEDB_T134.PUBLIC.SALES_CLONE_T134;| ROWS_IN_IT | TOTAL_AMOUNT |
|---|---|
| 7 | 1369.00 |
This is the part that cost a whole run. The teardown at the end of the demo script dropped CLONEDB_T134 using a bare name — and that was the database the session was sitting in, because creating it had moved the session there. Every cleanup statement after that was refused for having no current database, and the objects were left on the account.
That refusal is not one of the grids on this page. The script was fixed before this run, so there is no capture of it, and inventing an error pane for it would make this post exactly the kind of thing it is trying not to be. The teardown here puts the session somewhere it knows first and then uses fully qualified names, which you can see in the last section.
A few more things CLONE will not do
Four refusals, and each one tells you something about where the clause stops.
A source that is not there.
CREATE OR REPLACE TABLE NOSOURCE_T134 CLONE NOSUCHTABLE_T134;002003 (42S02): SQL compilation error: Object 'NOSUCHTABLE_T134' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have at least one privilege granted on TABLE NOSUCHTABLE_T134.
A target name that is already taken, written without OR REPLACE.
CREATE TABLE SALES_CLONE2_T134 CLONE SALES_T134;002002 (42710): SQL compilation error: Object 'SALES_CLONE2_T134' already exists.
002002, already exists. Now a view. Can a view be cloned?
CREATE OR REPLACE VIEW SALESVIEW_CLONE_T134 CLONE SALESVIEW_T134;001003 (42000): SQL compilation error: syntax error line 1 at position 50 unexpected 'SALESVIEW_T134'. syntax error line 1 at position 64 unexpected '<EOF>'.
001003, a syntax error. CREATE VIEW … CLONE is not a form the parser knows at all, which is a different kind of no from the next one.
CREATE OR REPLACE TABLE FROMVIEW_T134 CLONE SALESVIEW_T134;002118 (0A000): SQL compilation error: Cannot clone from a view object.
002118, Cannot clone from a view object. That statement parses, and then the clause refuses the source.
And a schema that does not exist.
CREATE OR REPLACE SCHEMA NOSCHEMA_T134 CLONE NOSUCHSCHEMA_T134;002003 (02000): SQL compilation error: Schema 'DEMO_DB.NOSUCHSCHEMA_T134' does not exist or not authorized. Your primary role ACCOUNTADMIN or one of your secondary roles must have USAGE or any other privilege granted on SCHEMA DEMO_DB.NOSUCHSCHEMA_T134.
One last thing: the pattern that matched nothing
The SHOW TABLES query above used LIKE '%\_T134', with a backslash in front of the underscore, and it matched both tables. Let's ask the catalog view the same thing four different ways.
SELECT COUNT(*) AS TABLES_ENDING_IN_T134
FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC'
AND ENDSWITH(TABLE_NAME, '_T134');| TABLES_ENDING_IN_T134 |
|---|
| 2 |
SELECT COUNT_IF(ENDSWITH(TABLE_NAME, '_T134')) AS BY_ENDSWITH,
COUNT_IF(TABLE_NAME LIKE '%\\_T134') AS BY_BACKSLASH_LIKE,
COUNT_IF(TABLE_NAME LIKE '%_T134') AS BY_PLAIN_LIKE,
COUNT_IF(TABLE_NAME LIKE '%\\_T134' ESCAPE '\\') AS BY_LIKE_WITH_ESCAPE
FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC';| BY_ENDSWITH | BY_BACKSLASH_LIKE | BY_PLAIN_LIKE | BY_LIKE_WITH_ESCAPE |
|---|---|---|---|
| 2 | 0 | 2 | 2 |
ENDSWITH finds two. A plain LIKE '%_T134' finds two. The same pattern with an ESCAPE clause finds two. And the backslash pattern on its own finds none.
Let's look at what that pattern actually is.
SELECT '%\\_T134' AS THE_PATTERN_AS_SNOWFLAKE_SEES_IT,
LENGTH('%\\_T134') AS HOW_MANY_CHARACTERS,
'SALES_T134' LIKE '%\\_T134' AS DOES_IT_MATCH,
'SALES_T134' LIKE '%\\_T134' ESCAPE '\\' AS WITH_AN_ESCAPE_CLAUSE,
'SALES_T134' LIKE '%_T134' AS PLAINLY;| THE_PATTERN_AS_SNOWFLAKE_SEES_IT | HOW_MANY_CHARACTERS | DOES_IT_MATCH | WITH_AN_ESCAPE_CLAUSE | PLAINLY |
|---|---|---|---|---|
| %\_T134 | 7 | FALSE | TRUE | TRUE |
Seven characters, and the backslash is one of them. Without an ESCAPE clause, LIKE is looking for a literal backslash in the table name, and there isn't one.
So a pattern that works in SHOW TABLES LIKE can find nothing in a WHERE clause, with no error either way. If you are counting your own objects, use ENDSWITH and sleep better.
And the cleanup, written for the wreckage
Every statement in the teardown names its database and schema in full, and the session is put somewhere it knows before any of them run. Then we check.
SELECT CURRENT_DATABASE() AS THE_DATABASE,
CURRENT_SCHEMA() AS THE_SCHEMA;| THE_DATABASE | THE_SCHEMA |
|---|---|
| DEMO_DB | PUBLIC |
SELECT COUNT(*) AS PROBE_TABLES_LEFT
FROM DEMO_DB.INFORMATION_SCHEMA.TABLES
WHERE TABLE_SCHEMA = 'PUBLIC'
AND ENDSWITH(TABLE_NAME, '_T134');| PROBE_TABLES_LEFT |
|---|
| 0 |
SELECT COUNT(*) AS PROBE_VIEWS_LEFT
FROM DEMO_DB.INFORMATION_SCHEMA.VIEWS
WHERE TABLE_SCHEMA = 'PUBLIC'
AND ENDSWITH(TABLE_NAME, '_T134');| PROBE_VIEWS_LEFT |
|---|
| 0 |
SELECT COUNT(*) AS PROBE_SCHEMAS_LEFT
FROM DEMO_DB.INFORMATION_SCHEMA.SCHEMATA
WHERE ENDSWITH(SCHEMA_NAME, '_T134');| PROBE_SCHEMAS_LEFT |
|---|
| 0 |
SHOW DATABASES LIKE '%T134';| created_on | name | is_default | is_current | origin | owner | comment | options | retention_time | kind | owner_role_type | object_visibility | data_quality_monitoring_settings | resharing_settings |
|---|
Nothing left, and the session is back in DEMO_DB.PUBLIC.
Key points
- A clone is a second name over data that is already stored.
SHOW TABLESreports1024bytes for the source and1024for the clone, for data stored once. - No column anywhere in that listing says a table is a clone.
- The clustering key travels.
automatic_clusteringdoes not — it isONfor the source andOFFfor the clone. - Write to either side and the other does not move.
- A clone outlives its source being dropped, because the storage was never the source's to own.
- Retention is copied at clone time. The clone made before the change kept
1day, the one made after it got3. - Transient cannot be cloned to permanent (
002120). The other direction is accepted. CLONE … BEFORE (STATEMENT => …)gives you a real table built from the past, not a query against it.- Cloning a schema re-points an unqualified reference and leaves a qualified one aimed at the original. The two views in the clone read
2and3rows. - A cloned schema does not bring its stages.
CREATE DATABASE … CLONEmoves your session into the new database, which changes what every unqualified name means.- So write a teardown that puts the session somewhere it knows and then names everything in full.
Episode 135 — streams. A bookmark into a table's change tracking, the three metadata columns a stream read gives you, and a stream that says it has data and then returns zero rows.
Every query and every result grid on this page was captured from a live Snowflake account (version 10.35.101) running the demo script for this episode. One grid is deliberately left out: the one that prints the statement id held in a session variable, because a query id belongs to one account's own history. The teardown failure described in the database section happened on an earlier run and was not captured, and no error pane is shown for it. Every count in the text is read off one of the grids on this page. Nothing is timed and no performance claims are made anywhere in this series. Behaviour follows the Snowflake CREATE … CLONE documentation.



No comments:
Post a Comment
Note: Only a member of this blog may post a comment.