Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

to get the list of schemas in postgresql db

by ansh batra (Friar)
on Nov 22, 2011 at 05:45 UTC ( #939369=perlquestion: print w/ replies, xml ) Need Help??
ansh batra has asked for the wisdom of the Perl Monks concerning the following question:

hi monks
how can i get the list of all the schemas present in a postgres database?

Comment on to get the list of schemas in postgresql db
Re: to get the list of schemas in postgresql db
by zwon (Monsignor) on Nov 22, 2011 at 06:29 UTC

    The same way you will do it without perl, select * from pg_namespace I guess.

      ur query is correct zwon but for that i need to connect to a database first
      cant we supply the database name in the query itself?? thanks

        Easy answer :) : No

        Enjoy, Have FUN! H.Merijn
Re: to get the list of schemas in postgresql db
by erix (Vicar) on Dec 04, 2011 at 11:27 UTC

    But TMTOWTDI (SQL standard compliant):

    select schema_name from information_schema.schemata where schema_name <> 'information_schema' -- exclude 'system' schemata and schema_name !~ E'^pg_' -- exclude more 'system' (pg +-specific)

    In psql there is \dn to retrieve schema names. If PGPASSFILE is set (and possibly more PG* environment variables like PGDATABASE), you can just talk to the database from the commandline:

    echo '\dn' | psql

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://939369]
Approved by planetscape
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (16)
As of 2014-10-24 16:23 GMT
Find Nodes?
    Voting Booth?

    For retirement, I am banking on:

    Results (133 votes), past polls