我使用Potgresql并编写了函数
CREATE OR REPLACE FUNCTION staging.shape_commit(layer_id integer)
RETURNS integer AS
$BODY$
declare
layer_name text;
begin
layer_name:=(select shape.layer_name from staging.shape where shape.id=layer_id);
delete from layer_name;
return layer_name;
end;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION staging.shape_commit(integer)
OWNER TO test;
layer_name是变量,实际上它是表名。但是脚本将其忽略为变量并用作字符串
Cam有人帮帮我吗?
答案 0 :(得分:0)
您的问题不是很明确,但我怀疑您确实希望将文本转换为表名。为此,您需要动态SQL。而不是:
delete from layer_name;
尝试更多类似的内容:
execute $x$delete from $x$ || layer_name::regclass;
http://www.postgresql.org/docs/current/static/plpgsql-statements.html