Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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
Replies are listed 'Best First'.
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 surveying the Monastery: (12)
As of 2015-11-25 14:48 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (679 votes), past polls