- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2024 08:45 AM
CREATE TABLE AS (CTAS) is a "one and done" kind of statement.
The new table retains no memory on how it came to be.
Therefore it will be oblivious to changes in the source.
Views, as you say, stored queries, no data is persisted. And therefore the query is run everytime the view is referenced. A view can "break" if the query gets sufficiently out of sync with the column list of the view - which is fixed at CREATE time.
Materialized views combine CTAS with VIEWs. They act like views in tracking updates to the data source content and they persist the data to sped you references.
However they do not tolerate changes to the schema of the data source (beyond ADD COLUMN).
To have the object "roll with the punches" so to speak, have a look at structured streaming and Delta Live Tables.