Lista wszystkich tabel w schemacie informacyjnym postgresql

Jaki jest najlepszy sposób na wyświetlenie wszystkich tabel w PostgreSQL ' s information_schema?

Dla wyjaśnienia: pracuję z pustym DB (nie dodałem żadnych własnych tabel), ale chcę zobaczyć każdą tabelę w strukturze information_schema.

Author: Brian Tompsett - 汤莱恩, 2010-02-17

7 answers

Powinieneś być w stanie po prostu uruchomić select * from information_schema.tables, aby uzyskać listę każdej tabeli zarządzanej przez Postgres dla konkretnej bazy danych.

Możesz również dodać where table_schema = 'information_schema', aby zobaczyć tylko tabele w schemacie informacyjnym.

 181
Author: RodeoClown,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-02-16 22:08:06

Do wyświetlania tabel użyj:

SELECT table_name FROM information_schema.tables WHERE table_schema='public'

Wyświetli tylko te tabele, które tworzysz.

 70
Author: phsaires,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-11-25 19:21:36
\dt information_schema.

Z psql, powinno być dobrze.

 31
Author: ,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-02-16 22:31:15

Polecenie "\z" jest również dobrym sposobem na wyświetlanie tabel wewnątrz interaktywnej sesji psql.

Np.

# psql -d mcdb -U admin -p 5555
mcdb=# /z
                           Access privileges for database "mcdb"
 Schema |              Name              |   Type   |           Access privileges
--------+--------------------------------+----------+---------------------------------------
 public | activities                     | table    |
 public | activities_id_seq              | sequence |
 public | activities_users_mapping       | table    |
[..]
 public | v_schedules_2                  | view     | {admin=arwdxt/admin,viewuser=r/admin}
 public | v_systems                      | view     |
 public | vapp_backups                   | table    |
 public | vm_client                      | table    |
 public | vm_datastore                   | table    |
 public | vmentity_hle_map               | table    |
(148 rows)
 8
Author: Chris Shoesmith,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-07-07 06:25:27

Możesz również użyć

select * from pg_tables where schemaname = 'information_schema'

In generall PG * tables all all you to see everything in the db, not constriced to your permissions (if you have access to the tables of course).

 7
Author: Tim,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-07-28 16:36:40

Dla prywatnego schematu 'xxx' w postgresql :

SELECT table_name FROM information_schema.tables 
 WHERE table_schema = 'xxx' AND table_type = 'BASE TABLE'

Bez table_type = 'BASE TABLE', będziesz wyświetlał tabele i widoki

 4
Author: germanlinux,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-04-03 20:20:33

Jeśli chcesz szybkie i brudne jednoliniowe zapytanie:

select * from information_schema.tables

Można go uruchomić bezpośrednio w narzędziu zapytań bez konieczności otwierania psql.

(inne posty sugerują ładne bardziej szczegółowe zapytania information_schema, ale jako nowy, znajduję to jednoliniowe zapytanie pomaga mi uporać się z tabelą)

 0
Author: Sally Levesque,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2018-02-07 11:46:56