【发布时间】:2021-03-26 05:40:52
【问题描述】:
我正在尝试在 stored procedure 中运行 copy 命令。
此复制命令从aws s3 复制到aws redshift 中的表
这是复制命令
copy schema1_ghsheet.ghseet_temp
from
''''s3://root2/rawfiles/''''
iam_role ''''arn:aws:iam::743:role/redshift''''
csv DELIMITER ',' IGNOREHEADER 1 TRUNCATECOLUMNS;
我正在尝试将其添加到存储过程中,现在看起来像这样。
我在这里尝试创建一个temp 表,其中包含来自s3 的所有数据,该表正在使用copy 命令复制到temp 表中。
CREATE OR REPLACE PROCEDURE proc_test() LANGUAGE plpgsql
AS
'
BEGIN
drop table if exists
schema1_ghsheet.ghseet_temp
;
create table
schema1_ghsheet.ghseet_temp(emp_id int, emp_name varchar(100),hrly_rate int,mod_timestamp timestamp)
;
copy schema1_ghsheet.ghseet_temp
from
''''s3://root2/rawfiles/''''
iam_role ''''arn:aws:iam::743:role/redshift''''
csv DELIMITER ',' IGNOREHEADER 1 TRUNCATECOLUMNS;
drop table if exists
schema1_ghsheet.ghseet_main
;
create table
schema1_ghsheet.ghseet_main
as
select h1.emp_id,h1.emp_name,h1.hrly_rate,h1.mod_timestamp
from schema1_ghsheet.ghseet_hstry h1
inner join (
select emp_id ,emp_name , max(mod_timestamp ) mod_timestamp
from schema1_ghsheet.ghseet_hstry
group by 1,2
) h2
on h1.emp_id=h2.emp_id
and h1.mod_timestamp=h2.mod_timestamp
group by 1,2,3,4
;
END;
'
但这会引发错误:
only one AS items needed for language "plpgsql";
那么,如何在stored procedure 中添加copy 命令还是需要单独调用copy 命令?
【问题讨论】:
标签: sql amazon-web-services stored-procedures amazon-redshift