我想在执行一些查询之前检查用户。我做了类似的事情:
DO $do$
BEGIN
IF(current_user=$$usrA$$) THEN
ALTER TYPE enum_to_change ADD VALUE $$myNewValue$$;
ELSE
SELECT $$ERROR$$; /*must crash here*/
END IF;
END $do$;
不起作用:
ERROR: ALTER TYPE ... ADD cannot be executed from a function or multi-command string
CONTEXT: SQL statement "ALTER TYPE e ADD VALUE 'myNewValue'"
PL/pgSQL function inline_code_block line 4 at SQL statement
有办法吗?
答案 0 :(得分:0)
https://www.postgresql.org/docs/current/static/sql-altertype.html
ALTER TYPE ... ADD VALUE(为枚举添加新值的表单) type)不能在事务块内执行。
https://www.postgresql.org/message-id/3543.1317224437%40sss.pgh.pa.us
The comment beside the code says what it breaks: case T_AlterEnumStmt: /* ALTER TYPE (enum) */ /* * We disallow this in transaction blocks, because we can't cope * with enum OID values getting into indexes and then having their * defining pg_enum entries go away. */
看起来你无法做到。这意味着行为......