I have a sql query which fetches the data from 4 tables and I want to use this script to load data into another table in Redshift and I am trying to create a stored procedure but I keep getting errors. Below is my script.
CREATE or replace PROCEDURE ABC1 (SOURCE_SYS CHAR(3), FILE_NBR BIGINT)
AS
BEGIN
INSERT INTO SP1 (SOURCE_SYS,FILE_NBR)
VALUES(
SELECT 'WT', PK_ORDERNO
FROM table_1
JOIN table_2 ON table_1.file_nbr = table_2.file_nbr
LEFT OUTER JOIN table_3 ON table_2.file_nbr = table_3.file_nbr
)
END;
You should do it this way:
CREATE OR REPLACE PROCEDURE ABC1 (SOURCE_SYS CHAR(3),FILE_NBR BIGINT)
AS $$
BEGIN
INSERT INTO SP1 (SOURCE_SYS,FILE_NBR)
SELECT 'WT',PK_ORDERNO FROM
table_1 join table_2 on table_1.file_nbr=table_2.file_nbr
left outer join
table_3 on table_2.file_nbr = table_3.file_nbr ;
END;
$$ LANGUAGE plpgsql;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.