0

我使用 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 是变量,实际上是表名。但是脚本将其作为变量忽略并用作字符串

卡有人帮我吗?

4

1 回答 1

0

您的问题不太清楚,但我怀疑您实际上想将文本转换为表名。为此,您需要动态 SQL。代替:

delete  from layer_name;

尝试更多类似的东西:

execute $x$delete from $x$ || layer_name::regclass;

http://www.postgresql.org/docs/current/static/plpgsql-statements.html

于 2013-10-29T09:07:43.083 回答