If I create a user in a group, like:
create role user_1 login inherit in role group_1;
later, with which query could I retrieve to which group(s) a user belongs to?
Use \du or \du+ psql command to list all users in the current database server. Use the SELECT statement to query the user information from the pg_catalog.
The PostgreSQL GROUP BY clause is used in collaboration with the SELECT statement to group together those rows in a table that have identical data. This is done to eliminate redundancy in the output and/or compute aggregates that apply to these groups.
To list the tables in the current database, you can run the \dt command, in psql : If you want to perform an SQL query instead, run this: SELECT table_name FROM information_schema.
Just to give a copy&pastable solution - On PostgreSQL (tested 8.4 and 9.3) you can do:
select rolname from pg_user join pg_auth_members on (pg_user.usesysid=pg_auth_members.member) join pg_roles on (pg_roles.oid=pg_auth_members.roleid) where pg_user.usename='USERNAME';
where USERNAME is the name of the login role you are interested in.
From the psql command line:
\dg
or
\du
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With