PostgreSQL 9.1:使用函数返回值对表设置注释

PostgreSQL 9.1:使用函数返回值对表设置注释,sql,postgresql-9.1,Sql,Postgresql 9.1,如果我使用这段代码在表上写注释,一切正常: 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" 你知道怎么解决这个问题吗?(我

如果我使用这段代码在表上写注释,一切正常:

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”系统表)

多谢各位。
Luca

您需要动态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$