From: | Pavel Luzanov <p(dot)luzanov(at)postgrespro(dot)ru> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "Jonathan S(dot) Katz" <jkatz(at)postgresql(dot)org>, Robert Haas <robertmhaas(at)gmail(dot)com>, David Zhang <david(dot)zhang(at)highgo(dot)ca>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, rmt(at)lists(dot)postgresql(dot)org, horikyota(dot)ntt(at)gmail(dot)com |
Subject: | Re: psql: Add role's membership options to the \du+ command |
Date: | 2023-07-13 08:26:07 |
Message-ID: | 50ea2597-5e3f-372c-1ea8-5ba4f3edd690@postgrespro.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On 08.07.2023 20:07, Tom Lane wrote
> 3. Not sure about use of LEFT JOIN in the query. That will mean we
> get a row out even for roles that have no grants, which seems like
> clutter. The LEFT JOINs to r and g are fine, but I suggest changing
> the first join to a plain join.
Hm.
Can you explain why LEFT JOIN to r and g are fine after removing LEFT
JOIN to pam?
Why not to change all three left joins to plain join?
The query for v16+ now looks like:
SELECT m.rolname AS "Role name", r.rolname AS "Member of",
pg_catalog.concat_ws(', ',
CASE WHEN pam.admin_option THEN 'ADMIN' END,
CASE WHEN pam.inherit_option THEN 'INHERIT' END,
CASE WHEN pam.set_option THEN 'SET' END
) AS "Options",
g.rolname AS "Grantor"
FROM pg_catalog.pg_roles m
JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)
LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)
LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)
WHERE m.rolname !~ '^pg_'
ORDER BY 1, 2, 4;
And for versions <16 I forget to simplify expression for 'Options'
column after removing LEFT JOIN on pam:
SELECT m.rolname AS "Role name", r.rolname AS "Member of",
pg_catalog.concat_ws(', ',
CASE WHEN pam.admin_option THEN 'ADMIN' END,
CASE WHEN pam.roleid IS NOT NULL AND m.rolinherit THEN 'INHERIT' END,
CASE WHEN pam.roleid IS NOT NULL THEN 'SET' END
) AS "Options",
g.rolname AS "Grantor"
FROM pg_catalog.pg_roles m
JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)
LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)
LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)
WHERE m.rolname !~ '^pg_'
ORDER BY 1, 2, 4;
I plan to replace it to:
pg_catalog.concat_ws(', ',
CASE WHEN pam.admin_option THEN 'ADMIN' END,
CASE WHEN m.rolinherit THEN 'INHERIT' END,
'SET'
) AS "Options",
--
Pavel Luzanov
Postgres Professional: https://postgrespro.com
From | Date | Subject | |
---|---|---|---|
Next Message | Shruthi Gowda | 2023-07-13 08:31:49 | Re: 'ERROR: attempted to update invisible tuple' from 'ALTER INDEX ... ATTACH PARTITION' on parent index |
Previous Message | Kyotaro Horiguchi | 2023-07-13 08:25:48 | Re: add non-option reordering to in-tree getopt_long |