我正在尝试从一个表导出数据以获得产品级的csv文件。我已经创建了一个函数,如下所示,但是Postgres在我试图运行它时,在包含产品的变量rec上抛出了一个错误。有没有人可以帮我排查函数的故障,找出错误?当我之前测试它时,如果我将数据插入到一个表中,它就会像预期的那样工作。
CREATE or replace FUNCTION exportdata()
RETURNS SETOF record AS
$$
DECLARE
rec text;
BEGIN
FOR rec IN
(
Select distinct t.products from trndailyprices as t
)
LOOP
Copy (
Select * from trndailyprices as t
where t.products = rec ---1st record is product1
order by t.effectivedate)
To 'C:/testQ/' ||rec || '.csv' With CSV;---expected file is product1.csv for 1st record
END LOOP;
END;
$$ LANGUAGE plpgsql;发布于 2015-04-26 03:59:28
Copy (Select * from trndailyprices as
order by effectivedate) To 'C:/testQ/test.csv' With CSV;从逻辑上讲,你的循环是加的。
https://stackoverflow.com/questions/29870009
复制相似问题