-2

What i want to do is to make a drop down list of all the databases of my postgresql 9.3 server using php . if i can get just the sql script that can do the trick then i can handle the php part.

Thanks for your time.

0

2 Answers 2

2

This information is stored in pg_database:

select datname
from pg_database;

Obviously you need to connect some database in order to be able to run the query.

1
  • for other users i have added some more in next answer. thanks .:) Jul 28, 2015 at 6:10
1
SELECT pg_database.datname as "Database",
       pg_user.usename as "postgres" FROM pg_database, pg_user
WHERE pg_database.datdba = pg_user.usesysid
UNION
SELECT pg_database.datname as "Database",
       NULL as "postgres" FROM pg_database
WHERE pg_database.datdba NOT IN (SELECT usesysid FROM pg_user)
ORDER BY "Database"  -- database that belong to user postgres

SELECT pg_database.datname as "Database" FROM pg_database; -- all databases 

SELECT datname FROM pg_database
WHERE datistemplate = false;

Not the answer you're looking for? Browse other questions tagged or ask your own question.