所以我想把一些值放在一起,因为它们具有相同的被授权者。但不幸的是,我找不到正确的查询。
下面是基本的查询(所以,这是可行的,但是由于“privilege_type”,有很多行):
SELECT
table_schema,
table_name,
grantee,
privilege_type
FROM
information_schema.role_table_grants
WHERE
table_schema='public';结果是:https://image.noelshack.com/fichiers/2019/36/5/1567753951-capture.png
所以现在我只想用"grantee“来表示一行。所以我需要把"privilege_type“的所有值放在一个数组中,每个”被授权者“。
我试过了,但它不起作用:
SELECT
table_schema,
table_name,
grantee,
ARRAY(SELECT privilege_type
FROM
information_schema.role_table_grants
GROUP BY grantee) as privileges
FROM
information_schema.role_table_grants
WHERE
table_schema='public';我怎么做才能...?所以我只能得到2行(例如前一张图片)…我真的不明白。
发布于 2019-09-06 15:38:01
您可以在array_agg()中使用group by
SELECT table_schema,
table_name,
grantee,
array_agg(privilege_type::text) as privileges
FROM information_schema.role_table_grants
WHERE table_schema='public'
GROUP BY table_schema, table_name, grantee;https://stackoverflow.com/questions/57817475
复制相似问题