Re: SQL query: List all the databases in the server - Mailing list pgsql-docs

From Tom Lane
Subject Re: SQL query: List all the databases in the server
Date
Msg-id 18380.994171549@sss.pgh.pa.us
Whole thread Raw
In response to Re: SQL query: List all the databases in the server  (Tom Ivar Helbekkmo <tih@kpnQwest.no>)
List pgsql-docs
Tom Ivar Helbekkmo <tih@kpnQwest.no> writes:
> The above SELECT is extensively reformatted from the strings it's
> built from in the source file, of course.

An even easier way to see what queries psql emits for its backslash
commands is to start psql with -E option, then do the backslash
commands.  This gives me, for example,

regression=# \l
********* QUERY **********
SELECT pg_database.datname as "Database",
       pg_user.usename as "Owner"FROM pg_database, pg_user
WHERE pg_database.datdba = pg_user.usesysid

UNION

SELECT pg_database.datname as "Database",
       NULL as "Owner"FROM pg_database
WHERE pg_database.datdba NOT IN (SELECT usesysid FROM pg_user)
ORDER BY "Database"
**************************

   List of databases
  Database  |  Owner
------------+----------
 regression | postgres
 template0  | postgres
 template1  | postgres
(3 rows)

regression=#

            regards, tom lane

pgsql-docs by date:

Previous
From: Tom Ivar Helbekkmo
Date:
Subject: Re: SQL query: List all the databases in the server
Next
From: Roman Smirnov
Date:
Subject: Re: SQL query: List all the databases in the server