Обсуждение: 'show databases' in psql way?

Поиск
Список
Период
Сортировка

'show databases' in psql way?

От
Erik Wasser
Дата:
Hi list,

how can I list the databases in a postgresish way? I know about the '-l' 
switch of 'psql' but is there a DBI/SQL-query way? I don't want to call 
an external program only to list the databases. I've googled about this 
problem but I only found the '-l'-way to this this.

Ideas? Solutions?

-- 
So long... Fuzz


Re: 'show databases' in psql way?

От
Frank Bax
Дата:
At 07:13 AM 11/1/04, Erik Wasser wrote:
>how can I list the databases in a postgresish way? I know about the '-l'
>switch of 'psql' but is there a DBI/SQL-query way? I don't want to call
>an external program only to list the databases. I've googled about this
>problem but I only found the '-l'-way to this this.


The -e switch of psql will display queries behind commands.  So use this 
option, the use 'l' as a command instead of a switch.

Frank



Re: 'show databases' in psql way?

От
Ian Barwick
Дата:
On Mon, 1 Nov 2004 13:13:10 +0100, Erik Wasser <erik.wasser@iquer.net> wrote:
> Hi list,
> 
> how can I list the databases in a postgresish way? I know about the '-l'
> switch of 'psql' but is there a DBI/SQL-query way? I don't want to call
> an external program only to list the databases. I've googled about this
> problem but I only found the '-l'-way to this this.
> 
> Ideas? Solutions?

Start psql with the -E switch, and it shows the SQL used to generate
the output from psql's slash commands.

Ian Barwick
barwick@gmail.com


Re: 'show databases' in psql way?

От
Erik Wasser
Дата:
On Monday 01 November 2004 13:26, Ian Barwick wrote:

> Start psql with the -E switch, and it shows the SQL used to generate
> the output from psql's slash commands.

Thanks for the quick answer. I will remember this switch! B-)

-- 
So long... Fuzz


Re: 'show databases' in psql way?

От
"Greg Sabino Mullane"
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
> how can I list the databases in a postgresish way? I know
> about the '-l' switch of 'psql' but is there a DBI/SQL-query way?
Yes, the DBI way is to use the "data_sources" function. Works
just fine for Postgres:
my @dbs = DBI->data_sources('Pg');
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200411012240
-----BEGIN PGP SIGNATURE-----
iD8DBQFBhwIHvJuQZxSWSsgRArd1AJ9hKXD+cSaM2L3RUXQdabuRofNFjwCfaHT0
+bRPuYhuED0mnlp1FRtvQQw=
=tsqe
-----END PGP SIGNATURE-----




Re: 'show databases' in psql way?

От
lorid
Дата:
\z   will list the tables in the dbase
\d tablename will list the columns in the table

---------------------
Erik Wasser wrote:

>Hi list,
>
>how can I list the databases in a postgresish way? I know about the '-l' 
>switch of 'psql' but is there a DBI/SQL-query way? I don't want to call 
>an external program only to list the databases. I've googled about this 
>problem but I only found the '-l'-way to this this.
>
>Ideas? Solutions?
>
>  
>



Re: 'show databases' in psql way?

От
Achilleus Mantzios
Дата:
O lorid έγραψε στις Nov 2, 2004 :

> \z   will list the tables in the dbase
> \d tablename will list the columns in the table
> 

or 
foodb=# SELECT oid,* from pg_database ;

> ---------------------
> Erik Wasser wrote:
> 
> >Hi list,
> >
> >how can I list the databases in a postgresish way? I know about the '-l' 
> >switch of 'psql' but is there a DBI/SQL-query way? I don't want to call 
> >an external program only to list the databases. I've googled about this 
> >problem but I only found the '-l'-way to this this.
> >
> >Ideas? Solutions?
> >
> >  
> >
> 
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
> 
>                http://www.postgresql.org/docs/faqs/FAQ.html
> 

-- 
-Achilleus



Re: 'show databases' in psql way?

От
"Arash Zaryoun"
Дата:
in command line: psql template1 pgsql -l

in PSQL:
foodb=#> select datname from pg_database;

- Arash

>>> Achilleus Mantzios <achill@matrix.gatewaynet.com> 11/2/2004 10:21:06 AM >>>
O lorid ****** **** Nov 2, 2004 :

> \z   will list the tables in the dbase
> \d tablename will list the columns in the table
>

or
foodb=# SELECT oid,* from pg_database ;

> ---------------------
> Erik Wasser wrote:
>
> >Hi list,
> >
> >how can I list the databases in a postgresish way? I know about the '-l'
> >switch of 'psql' but is there a DBI/SQL-query way? I don't want to call
> >an external program only to list the databases. I've googled about this
> >problem but I only found the '-l'-way to this this.
> >
> >Ideas? Solutions?
> >
> >
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
>                http://www.postgresql.org/docs/faqs/FAQ.html
>

--
-Achilleus


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?
              http://www.postgresql.org/docs/faqs/FAQ.html



Re: 'show databases' in psql way?

От
"Greg Sabino Mullane"
Дата:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
To be pedantic about it, use:
SELECT pg_catalog.quote_ident(datname) AS database
FROM pg_catalog.pg_database ORDER BY 1;
or if using version 8 or higher:
SELECT pg_catalog.quote_ident(datname) AS database,
pg_catalog.quote_ident(spcname) AS tablespace
FROM pg_catalog.pg_database
JOIN pg_catalog.pg_tablespace t ON (dattablespace=t.oid)
ORDER BY 1;
- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200411022120
-----BEGIN PGP SIGNATURE-----
iD8DBQFBiFTSvJuQZxSWSsgRApflAJ0RiVndbc6u//cXX/S7uM8K91lWbgCfYVbC
MsRNWlP446AcvHm0UaGgEVo=
=S8Ft
-----END PGP SIGNATURE-----