![](/img/trans.png)
[英]Returning table with specific parameters from a PostgreSQL function
[英]PostgreSQL 9.1: set comment on table with returning value from a function
如果我使用这段代码在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”系统表)
谢谢。 卢卡
为此,您需要动态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$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.