Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

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 (Abbot) 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 (Parson) 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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2018-06-21 01:47 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.