查询授予postgres序列的GRANTS

mar*_*kus 8 sql postgresql sequence grant

要查询授予表的GRANTS,我可以使用如下查询:

SELECT grantee, privilege_type 
FROM information_schema.role_table_grants 
WHERE table_name='mytable'
Run Code Online (Sandbox Code Playgroud)

(请参阅我在这里的旧问题:查询postgres中的表格授予)

但是我如何查询GRANTS被授予一个序列?

Mik*_*ll' 7

我查看了源代码,我找不到任何通过information_schema表公开序列ACL的地方.(不过我可能会错过一些东西.)

PostgreSQL确实公开了系统目录pg_class中序列的ACL.

SELECT relname, relacl
FROM pg_class
WHERE relkind = 'S'
  AND relacl is not null
  AND relnamespace IN (
      SELECT oid
      FROM pg_namespace
      WHERE nspname NOT LIKE 'pg_%'
        AND nspname != 'information_schema'
);
Run Code Online (Sandbox Code Playgroud)

就information_schema和标准SQL序列而言,PostgreSQL不支持它们.

select feature_name, is_supported 
from information_schema.sql_features
where feature_name = 'Sequence generator support';
Run Code Online (Sandbox Code Playgroud)

PostgreSQL在这方面是不合格的,因为它暴露了information_schema.sequences而没有为'Sequence generator support'返回"YES".(这是一个观察,而不是对PostgreSQL的批评.)

但是,说了这么多,我在2003 SQL标准中找不到任何暴露这些特权的东西.在ROLE_TABLE_GRANTS视图的定义中很容易找到PRIVILEGE_TYPE,但据我所知,标准中的序列没有类似的东西.

  • 除了 @MikeSherrill'CatRecall' 的解释之外,使用他发布的对“pg_class”的查询,您可以使用“relacl”列内容推断出授予序列的权限。第一个设置(第一个逗号之前)将是序列所有者权限:“owner=rwU/owner”,其中 r 将是读取权限(“currval”),w 将是写入权限(“nextval”和“setval”),U 将是用法(“currval”和“nextval”)。由于您通常只授予“使用”和“选择”权限,因此其他 acl 看起来像“grantee=rU/owner” (2认同)
  • 我在其他线程上找到了这个,它对我有用:`select * from information_schema.role_usage_grants` (2认同)