I’m trying to test a simple CURSOR
statement in Snowflake, which is almost identical to the code in the official documentation. All my example should do is to retrieve dates from a source table, and insert them one by one into a destination table. Here is my code:
CREATE OR REPLACE TEMPORARY TABLE InDates (InDate DATE);
INSERT INTO InDates
SELECT DISTINCT Analysis_Date FROM RawData
WHERE ANALYSIS_DATE > '2024-06-25';
CREATE OR REPLACE TEMPORARY TABLE OutDates (OutDate DATE);
DECLARE
c1 CURSOR FOR SELECT InDate FROM InDates;
BEGIN
FOR record IN c1 DO
INSERT INTO OutDates(OutDate)
SELECT record.InDate;
END FOR;
END;
When I try to run this it yields the error invalid identifier 'RECORD.INDATE' (line 15)
. But it no examples (official or otherwise) does it show the need to declare RECORD
anywhere. Am I missing something obvious?