How to do a simple loop for insert in Amazon Redshift?

Viewed 21

I would like to do a very simple pl/sql transaction with loop and for to insert values into a table. It should work like this:

CREATE PROCEDURE cs_refresh_reports() AS $$
DECLARE
  last_nps RECORD;
BEGIN

  FOR last_nps IN SELECT "date" FROM table_1 ;
  LOOP
  EXECUTE insert into table_2 ("value") select "value" from table_3 where "date" = :last_nps ;
  END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql; 

Very simple but I didn't find any solution for this and if I try I just get errors.

0 Answers
Related