MySQL i MariaDB mają SHOW TABLES instrukcja, która wyświetla listę tabel i widoków w bazie danych. PostgreSQL nie ma SHOW TABLES oświadczenie, ale ma polecenie, które daje podobny wynik.
W Postgresie możesz użyć \dt polecenie, aby wyświetlić listę tabel. To jest polecenie psql (psql to interaktywny terminal dla PostgreSQL).
Przykład
Oto przykład listy wszystkich tabel w PostgreSQL:
\dt Wynik:
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)
W tym przypadku wyświetla wszystkie tabele.
Mogliśmy użyć \d bez t Jeśli wymagane. Korzystanie z \d sam jest odpowiednikiem użycia \dtvmsE który pokazuje listę wszystkich widocznych tabel, widoków, widoków zmaterializowanych, sekwencji i tabel obcych. t w \dt to ogranicza dane wyjściowe tylko do tabel.
Określ nazwę tabeli
Możemy dodać do polecenia wzorzec, aby zwrócić tylko te tabele, które pasują do wzorca.
Przykład:
\dt pet* Wynik:
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)
Zwróć więcej informacji o stole
Możemy dołączyć \dt z + znak, aby uzyskać więcej informacji o każdej tabeli:
\dt+ pet* Wynik:
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)
Tym razem możemy zobaczyć rozmiar każdego stołu.