sql - 在执行查询之前检查用户
问题描述
我想在执行一些查询之前检查用户。我做这样的事情:
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
有没有办法做到这一点 ?
解决方案
https://www.postgresql.org/docs/current/static/sql-altertype.html
ALTER TYPE ... ADD VALUE(向枚举类型添加新值的形式)不能在事务块内执行。
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. */
看起来你做不到。这意味着行为...
推荐阅读
- uwp - Segoe MDL2 资产 - 更改或重置密码按钮的图标
- powerbi - PowerQuery Table.Join 重复的列名
- javascript - 为什么screep教程中出现Condition
- python - 如何删除 Python 列表中的每个第 n 个术语
- javascript - 如何在 JavaScript 中将“范围”的值转换为浮点数?
- swagger - @nestjs/swagger 为 GET 请求生成查询对象
- python - 如何更改cefpython窗口图标?
- python - 如何创建一个程序,该程序需要用户输入美国时间并使用 python 将其转换为 BG 时间?
- docker - Docker-compose 服务器无法访问
- amazon-web-services - 使用 GPU 在 EC2 实例上训练 Keras 模型很慢