0
我在postgres中創建一個函數,並得到奇怪的錯誤。我究竟做錯了什麼?我也想看看你的變異怎麼辦呢Postgres函數錯誤
CREATE OR REPLACE FUNCTION export_csv(request TEXT, filename VARCHAR(255))
RETURNS VOID AS
$$
BEGIN
EXECUTE 'COPY (' || request || ') TO "/home/r90t/work/study/etl/postgres_etl/export/' || filename || '" WITH CSV;';
END
$$
LANGUAGE plpgsql;
請求:
SELECT export_csv('SELECT * FROM orders', 'orders.csv')
錯誤:
psql:/tmp/vUp267V/dbext.sql:2: ERROR: syntax error at or near ""/home/r90t/work/study/etl/postgres_etl/export/orders.csv""
LINE 1: COPY (SELECT * FROM orders) TO "/home/r90t/work/study/etl/po...
^$
QUERY: COPY (SELECT * FROM orders) TO "/home/r90t/work/study/etl/postgres_etl/export/orders.csv" WITH CSV;
CONTEXT: PL/pgSQL function export_csv(text,character varying) line 3 at EXECUTE statement
字符串文字需要用單引號引起來,而不是雙引號。 –