雪花过程“STATMENT_ERROR”

问题描述 投票:0回答:1

我正在尝试调用雪花过程来获取我的数据的 CDC 记录。我遇到以下问题

错误:第 20 行第 12 处的“STATMENT_ERROR”:SQL 编译错误:第 87 行处的错误第 1 行(第 57 行) 无效标识符“SALESFORCE_ID”(第 57 行)

我在只有插入的表顶部创建了流。我循环遍历流中的每条记录,查找history_cdc表中是否有id,更新其元列并插入新记录。如果cdc表中没有id,我插入一条新记录。

不知道语句错误到底在哪里

create or replace procedure public.proc_get_cdc()
returns varchar(16777216)
language sql
execute as owner
as 
$$
declare
    max_meta_created timestamp_ntz;
    c1 cursor for select * from public.streams_static;
    exists_flag integer default 0;
    id varchar;
begin
    create or replace table public.streams_static as select * from public.dummy_streams;

    select max(meta_created) into max_meta_created from public.leads_history_cdc;

    if (max_meta_created is null) then
        insert into public.history_cdc(data, meta_created, meta_updated, meta_start, meta_expiry, meta_active_row, meta_operation) 
        select parse_json(data), meta_created, meta_updated, current_date, '2049-12-31', true, METADATA$ACTION from public.streams_static;
    end if;
    else
    for record in c1 do
            id:= parse_json(record.data):Id::varchar;

            select count(*) into exists_flag from public.leads_history_cdc where parse_json(data):Id::varchar = id;

            if (exists_flag > 0) then
                update public.history_cdc 
                set 
                    meta_expiry = (select max(meta_created) from public.streams_static where parse_json(data):Id::varchar = id),
                    meta_operation = 'delete',
                    meta_active_row = false,
                    meta_updated = (select max(meta_created) from public.streams_static where parse_json(data):Id::varchar = id)
                where 
                    parse_json(data):Id::varchar = id 
                    and meta_created = (select max(meta_created) from public.leads_history_cdc where parse_json(data):Id::varchar = id);

                insert into public.history_cdc(data, meta_created, meta_updated, meta_active_row, meta_operation, meta_start, meta_expiry)
                select parse_json(data), current_date, current_date, true, 'insert', current_date, '2049-12-31' from public.streams_static where parse_json(data):Id::varchar = id;
            else
                insert into public.history_cdc(data, meta_created, meta_updated, meta_active_row, meta_operation, meta_start, meta_expiry)
                select parse_json(data), current_date, current_date, true, 'insert', current_date, '2049-12-31' from public.streams_static where parse_json(data):Id::varchar = id;
            end if;
    end for;

    drop table public.streams_static;

    return null;
end;
$$;
sql stored-procedures snowflake-cloud-data-platform
1个回答
0
投票

我不确定, 但是基于 SQL 的雪花存储过程存在“insert into”命令的问题,因为对于存储过程,“into”关键字用于标识符。

过去我曾在 Snowflake 中提出过要求,但没有得到任何有效的理由。 问题链接。

使用雪花脚本插入数据的存储过程

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.