Fai*_*ani 4 etl snowflake-cloud-data-platform
我正在将表流用于我的 ETL 管道。我只是想知道是否有可能手动刷新表流中的数据而不将其保存在其他表中的任何位置?
当 Snowflake 在 DML 语句中看到 FROM 之后的流时,它会推进该流。它不关心您如何或是否使用行,因此您可以这样做:
insert into JUNK_TABLE select ANY_COLUMN from MY_STREAM where false;
Run Code Online (Sandbox Code Playgroud)
如果您只运行插入的这一部分,您可以看到不会插入任何内容:
select ANY_COLUMN from MY_STREAM where false;
Run Code Online (Sandbox Code Playgroud)
该where子句对于每一行的计算结果都为 false,因为这就是它设置的返回值。这意味着该insert语句不会插入一行,但会消耗流。
这是一个用于测试这一点的迷你脚本:
-- Quick setup:
create or replace table MY_TABLE(COL1 varchar);
create or replace stream MY_STREAM on table MY_TABLE;
--Create a junk table so the syntax works:
create table JUNK_TABLE like MY_TABLE;
insert into MY_TABLE(COL1) values ('Row1'), ('Row2'), ('Row3');
select * from MY_STREAM; --The stream has three rows
insert into JUNK_TABLE select COL1 from MY_STREAM where false; --Consume the stream
select * from MY_STREAM; -- The stream has no rows
select * from JUNK_TABLE; -- Neither does the junk table because "where false" on the insert
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3013 次 |
| 最近记录: |