Snowflake material view breaks on table swap

Viewed 72

We are ingesting data using a COPY INTO statement triggered by an external orchestration tool. The ingest is a full table load each time - I know, not ideal but it is what we currently have.

To get this ingested data to the final table, we clone the target, truncate the data, then insert the new ingested data. We then swap this with the target. This was working well but then someone put a materialized view on the target. Now this table swap causes the materialized view to become invalid each time the target is updated.

I should probably rewrite this to perform a merge into the target instead but that would be more complicated to write as there are no keys on this table, so I am wondering what the preferred solution is here?

Is is possible to force refresh a materialized view after a table swap or does it have to be rebuilt each time?

1 Answers

I think you found a bug in Snowflake and you should report it to Snowflake Support. My investigation shows that after executing the SWAP command, the view in the definition refers to the correct view, but in the metadata it switches to another table, it probably should not be so. Below is a screenshot from the SHOW MATERIALIZED VIEWS command:

enter image description here

Related