如果我使用这段代码在TABLE上写注释一切正常:
COMMENT ON TABLE schemaname.tablename IS 'Some Comment';
但是如果我想使用函数的返回值作为注释的值我有错误,就像这里:
COMMENT ON TABLE schemaname.tablename IS substring('Thomas' from 2 for 3);
ERROR: syntax error at or near "substring"
有关如何解决此问题的任何想法? (我不想编辑'pg_catalog.pg_description'系统表)
谢谢。 卢卡
答案 0 :(得分:1)
您需要动态SQL:
do
$body$
declare
comment_string text;
begin
comment_string := substr('thomas', 2, 3);
execute 'comment on table public.foo is '||quote_literal(comment_string);
commit;
end;
$body$