我有这个postgresql函数
CREATE OR REPLACE FUNCTION sp_select_test(_id bigint)
RETURNS void AS
$BODY$
BEGIN
copy (select sub.id
from (
SELECT id FROM sim s where id = _id) sub) TO '/tmp/results.tsv';
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION sp_select_test(bigint)
OWNER TO postgres;
当我跑步时
select * from sp_select_test(264);
我收到错误 - 列" _id"不存在
如果我用函数264替换函数中的变量_id,则该函数有效。也就是说,如果不是id = _id,我使用id = 264
该功能失败的原因是什么?
答案 0 :(得分:1)
CREATE OR REPLACE FUNCTION sp_select_test(_id bigint)
RETURNS void AS
$BODY$
BEGIN
execute $$copy (select sub.id
from (
SELECT id FROM sim s where id = $$||_id||$$) sub) TO '/tmp/results.tsv'$$;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION sp_select_test(bigint)
OWNER TO postgres;