Thread: Get a list of databases?

Get a list of databases?

From
"Neil Aggarwal"
Date:
Hello:

My code needs to be able to allow the user to select which
database to connect to.

Is there a programmatic way to get a list of the databases
managed by a pgsql server?

Thanks,
    Neil

--
Neil Aggarwal, (214)986-3533, www.JAMMConsulting.com
FREE! Eliminate junk email and reclaim your inbox.
Visit http://www.spammilter.com for details.


Re: Get a list of databases?

From
"A. Kretschmer"
Date:
am  Mon, dem 26.02.2007, um 22:52:57 -0600 mailte Neil Aggarwal folgendes:
> Hello:
>
> My code needs to be able to allow the user to select which
> database to connect to.
>
> Is there a programmatic way to get a list of the databases
> managed by a pgsql server?

You can use the output from following command:

psql -l


Andreas
--
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)
GnuPG-ID:   0x3FFF606C, privat 0x7F4584DA   http://wwwkeys.de.pgp.net

Re: Get a list of databases?

From
joseph speigle
Date:
>
> My code needs to be able to allow the user to select which
> database to connect to.
>
> Is there a programmatic way to get a list of the databases
> managed by a pgsql server?
you mean like 'psql >\l' ?
try
select datname from pg_database;
--
joe speigle
www.sirfsup.com

Re: Get a list of databases?

From
Kevin Hunter
Date:
On 27 Feb 2007 at 3:12p +0900, Joseph Speigle wrote:
>> My code needs to be able to allow the user to select which
>> database to connect to.
>>
>> Is there a programmatic way to get a list of the databases
>> managed by a pgsql server?
> you mean like 'psql >\l' ?
> try
> select datname from pg_database;

I found that setting the ECHO_HIDDEN psql runtime variable to be fairly
informative with something like this.  It basically explains exactly the
queries it runs against the DB to do anything.  Either from the
commandline or in your .psqlrc file:

\set ECHO_HIDDEN TRUE

Then do something mundane like '\d'.

HTH,

Kevin