MySQL a MariaDB mají SHOW TABLES výpis, který vypíše seznam tabulek a pohledů v databázi. PostgreSQL nemá SHOW TABLES příkaz, ale má příkaz, který produkuje podobný výsledek.
V Postgresu můžete použít \dt příkaz pro zobrazení seznamu tabulek. Toto je příkaz psql (psql je interaktivní terminál pro PostgreSQL).
Příklad
Zde je příklad výpisu všech tabulek v PostgreSQL:
\dt Výsledek:
List of relations Schema | Name | Type | Owner --------+------------------+-------+---------- public | albums | table | barney public | artists | table | barney public | customers | table | barney public | employees | table | barney public | genres | table | barney public | owners | table | postgres public | petbyid | table | postgres public | pets | table | postgres public | pets2 | table | postgres public | pets3 | table | postgres public | petstypesowners | table | postgres public | petstypesowners2 | table | postgres public | pettypecount | table | postgres public | pettypes | table | postgres public | students | table | barney public | t1 | table | barney public | teachers | table | barney (17 rows)
V tomto případě zobrazí všechny tabulky.
Mohli jsme použít \d bez t je-li potřeba. Pomocí \d samotný je ekvivalentem použití \dtvmsE který zobrazuje seznam všech viditelných tabulek, pohledů, materializovaných pohledů, sekvencí a cizích tabulek. t v \dt je to, co omezuje výstup pouze na tabulky.
Zadejte název tabulky
Můžeme k příkazu připojit vzor, abychom vrátili pouze ty tabulky, které se vzoru shodují.
Příklad:
\dt pet* Výsledek:
List of relations Schema | Name | Type | Owner --------+------------------+-------+---------- public | petbyid | table | postgres public | pets | table | postgres public | pets2 | table | postgres public | pets3 | table | postgres public | petstypesowners | table | postgres public | petstypesowners2 | table | postgres public | pettypecount | table | postgres public | pettypes | table | postgres (8 rows)
Vrátit další podrobnosti o tabulce
Můžeme připojit \dt s + podepsat, abyste jej dostali k výstupu více informací o každé tabulce:
\dt+ pet* Výsledek:
List of relations Schema | Name | Type | Owner | Size | Description --------+------------------+-------+----------+------------+------------- public | petbyid | table | postgres | 0 bytes | public | pets | table | postgres | 8192 bytes | public | pets2 | table | postgres | 8192 bytes | public | pets3 | table | postgres | 8192 bytes | public | petstypesowners | table | postgres | 16 kB | public | petstypesowners2 | table | postgres | 16 kB | public | pettypecount | table | postgres | 8192 bytes | public | pettypes | table | postgres | 8192 bytes | (8 rows)
Tentokrát můžeme vidět velikost každé tabulky.