Re: listing databases

Поиск
Список
Период
Сортировка
От Tod McQuillin
Тема Re: listing databases
Дата
Msg-id Pine.GSO.4.21.0011011008290.6485-100000@sysadmin
обсуждение исходный текст
Ответ на Re: listing databases  (Tod McQuillin <devin@spamcop.net>)
Список pgsql-php
On Wed, 1 Nov 2000, Tod McQuillin wrote:

> On Wed, 1 Nov 2000, magnus wrote:
>
> > Hello,
> > Can anyone tell me how to list (1.) databases and (2.) tables in a
> > database using php?
>
> To list databases, run
>
>     psql -l

Sorry, I didn't notice that you wanted to do it from php.  Even so, the
answer is almost the same.

If you run "psql -E -l" you get this:

devin@glass ~% psql -E -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"
*************************

That gives you the query that psql runs.

after you connect with psql -E, \dt tells you:

SELECT c.relname as "Name", 'table'::text as "Type", u.usename as "Owner"
FROM pg_class c, pg_user u
WHERE c.relowner = u.usesysid AND c.relkind = 'r'
  AND not exists (select 1 from pg_views where viewname = c.relname)
  AND c.relname !~ '^pg_'
UNION
SELECT c.relname as "Name", 'table'::text as "Type", NULL as "Owner"
FROM pg_class c
WHERE c.relkind = 'r'
  AND not exists (select 1 from pg_views where viewname = c.relname)
  AND not exists (select 1 from pg_user where usesysid = c.relowner)
  AND c.relname !~ '^pg_'

ORDER BY "Name"

Those are the queries you should run from php.
--
Tod McQuillin



В списке pgsql-php по дате отправления:

Предыдущее
От: Tod McQuillin
Дата:
Сообщение: Re: listing databases
Следующее
От: "Adam Lang"
Дата:
Сообщение: Re: listing databases