1

Postgresql allows adding comments to roles and users. For example I've added a comment to role "myuser" by using this SQL command:

COMMENT ON ROLE myuser IS 'User comment...';

My question is: If I want to use a SQL-command to get all users along with their respective comment - how would I do this? What would be the appropriate query for this?

1

2 Answers 2

2

You need to use built-in function shobj_description(object_oid, catalog_name)

SELECT *, shobj_description(oid, 'pg_authid') AS comment
  FROM pg_roles;
Sign up to request clarification or add additional context in comments.

Comments

1
SELECT u.usesysid, u.usename, d.description
FROM pg_catalog.pg_user u
   LEFT JOIN pg_catalog.pg_shdescription d
      ON d.objoid = u.usesysid
         AND classoid = 'pg_catalog.pg_authid'::regclass;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.