0

I'm trying to get a list of schemata in PostgreSQL (9.6) along with any comments which might have been added...

This works great to get a list of schema names:

select schema_name
from information_schema.schemata

...but how do you get the associated comment (if there is one) as well?

  • I've found loads of stuff to get database/table/column comments... schema comments seem to be evading me?

Any help gratefully received!

asked May 11, 2017 at 16:25

1 Answer 1

2

Use pg_namespace

select nspname as schemaname, 
 obj_description(oid, 'pg_namespace') as comment
from pg_namespace;

A good way to learn statements like that is to run psql with the --echo-hidden option and then use one of the meta commands to display the information.

If you e.g. run \dn+ in psql you see:

postgres=> \dn+
********* QUERY **********
SELECT n.nspname AS "Name",
 pg_catalog.pg_get_userbyid(n.nspowner) AS "Owner",
 pg_catalog.array_to_string(n.nspacl, E'\n') AS "Access privileges",
 pg_catalog.obj_description(n.oid, 'pg_namespace') AS "Description"
FROM pg_catalog.pg_namespace n
WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'
ORDER BY 1;
**************************
 List of schemas
 Name | Owner | Access privileges | Description
-----------+----------+----------------------+------------------------
 public | postgres | postgres=UC/postgres+| standard public schema
 | | =UC/postgres |
 stuff | postgres | |
 tablefunc | postgres | postgres=UC/postgres+|
answered May 11, 2017 at 16:27
Sign up to request clarification or add additional context in comments.

1 Comment

This is perfect... and thanks for the great tip @a_horse_with_no_name !

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.