-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add postfresql list table post
- Loading branch information
1 parent
ca86f6d
commit 1ef8ac1
Showing
4 changed files
with
448 additions
and
0 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
blog/list-tables-in-postgresql/list-tables-in-postgresql.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
slug: list-tables-in-postgresql | ||
title: "How to list tables in PostgreSQL" | ||
description: This article introduces two methods to list tables in a PostgreSQL database. PostgreSQL provides two ways to list all tables in a database. | ||
authors: owen | ||
image: https://cdn.illacloud.com/illa-website/blog/list-tables-in-postgresql/cover.webp | ||
tags: [postgres, postgresql, database, list, tables, psql] | ||
date: 2024-01-04T10:00 | ||
--- | ||
|
||
This article introduces two methods to list tables in a PostgreSQL database. PostgreSQL provides two ways to list all tables in a database: | ||
|
||
- Use `\dt` or `\dt+` in the `psql` tool to list all tables in the current database. | ||
- Query all tables from the `pg_tables` table. | ||
|
||
## List Tables in the Database Using \dt | ||
|
||
This example demonstrates the process of logging into the database using the `psql` tool and listing tables in the database. Follow these steps: | ||
|
||
1. Log in to the PostgreSQL server using the postgres user: | ||
|
||
```shell | ||
[~] psql -U postgres | ||
psql (14.4) | ||
Type "help" for help. | ||
``` | ||
|
||
Note: You can also use any user with the appropriate database permissions. | ||
|
||
2. Select the `testdb` database with the following statement: | ||
|
||
```shell | ||
\c testdb; | ||
``` | ||
|
||
If the database hasn't been created yet, run the following statement: | ||
|
||
```shell | ||
CREATE DATABASE testdb; | ||
``` | ||
|
||
3. Use the `\dt` command to list all tables in the `testdb` database: | ||
|
||
```shell | ||
\dt | ||
``` | ||
|
||
```shell | ||
List of relations | ||
Schema | Name | Type | Owner | ||
--------+----------------+-------+---------- | ||
public | mytable | table | postgres | ||
public | product | table | postgres | ||
public | test_date | table | postgres | ||
public | test_time | table | postgres | ||
public | test_timestamp | table | postgres | ||
public | week_day_sales | table | postgres | ||
(6 rows) | ||
``` | ||
|
||
4. If you want to view more information about the tables, use the `\dt+` command: | ||
|
||
```shell | ||
\dt+ | ||
``` | ||
|
||
```shell | ||
List of relations | ||
Schema | Name | Type | Owner | Persistence | Access method | Size | Description | ||
--------+----------------+-------+----------+-------------+---------------+------------+------------- | ||
public | mytable | table | postgres | permanent | heap | 16 kB | | ||
public | product | table | postgres | permanent | heap | 16 kB | | ||
public | test_date | table | postgres | permanent | heap | 8192 bytes | | ||
public | test_time | table | postgres | permanent | heap | 8192 bytes | | ||
public | test_timestamp | table | postgres | permanent | heap | 8192 bytes | | ||
public | week_day_sales | table | postgres | permanent | heap | 8192 bytes | | ||
(6 rows) | ||
``` | ||
|
||
You can see that the input of `\dt+` includes columns such as `Persistence`, `Access method`, `Size`, and `Description` in addition to the output of `\dt`. | ||
|
||
## Query Tables from the pg_tables Table | ||
|
||
In addition to the `\dt` and `\dt+` commands, you can also query all tables in the current data from the `pg_tables` table. | ||
|
||
The `pg_tables` table is a built-in table in PostgreSQL that stores all tables in the database. | ||
|
||
```shell | ||
SELECT * FROM pg_tables | ||
WHERE schemaname = 'public'; | ||
``` | ||
|
||
```shell | ||
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity | ||
------------+----------------+------------+------------+------------+----------+-------------+------------- | ||
public | test_date | postgres | | t | f | f | f | ||
public | test_time | postgres | | t | f | f | f | ||
public | test_timestamp | postgres | | t | f | f | f | ||
public | week_day_sales | postgres | | t | f | f | f | ||
public | mytable | postgres | | f | f | f | f | ||
public | product | postgres | | t | f | f | f | ||
(6 rows) | ||
``` | ||
|
||
## Conclusion | ||
|
||
PostgreSQL provides two ways to list all tables in a database: | ||
|
||
- Use `\dt` or `\dt+` in the psql tool to list all tables in the current database. | ||
- Query all tables from the `pg_tables` table. | ||
|
||
In MySQL, you can use the `SHOW TABLES` command to list databases. |
112 changes: 112 additions & 0 deletions
112
...urus-plugin-content-blog/list-tables-in-postgresql/list-tables-in-postgresql.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
slug: list-tables-in-postgresql | ||
title: "Wie man Tabellen in PostgreSQL auflistet" | ||
description: Dieser Artikel stellt zwei Methoden vor, um Tabellen in einer PostgreSQL-Datenbank aufzulisten. PostgreSQL bietet zwei Möglichkeiten, alle Tabellen in einer Datenbank aufzulisten. | ||
authors: owen | ||
image: https://cdn.illacloud.com/illa-website/blog/list-tables-in-postgresql/cover.webp | ||
tags: [postgres, postgresql, database, list, tables, psql] | ||
date: 2024-01-04T10:00 | ||
--- | ||
|
||
Dieser Artikel stellt zwei Methoden vor, um Tabellen in einer PostgreSQL-Datenbank aufzulisten. PostgreSQL bietet zwei Möglichkeiten, alle Tabellen in einer Datenbank aufzulisten: | ||
|
||
- Verwenden Sie `\dt` oder `\dt+` im `psql`-Tool, um alle Tabellen in der aktuellen Datenbank aufzulisten. | ||
- Abfragen Sie alle Tabellen aus der Tabelle `pg_tables`. | ||
|
||
## Auflisten von Tabellen in der Datenbank mit \dt | ||
|
||
Dieses Beispiel zeigt den Vorgang des Einloggens in die Datenbank mit dem `psql`-Tool und dem Auflisten von Tabellen in der Datenbank. Befolgen Sie diese Schritte: | ||
|
||
1. Melden Sie sich beim PostgreSQL-Server mit dem Benutzer postgres an: | ||
|
||
```shell | ||
[~] psql -U postgres | ||
psql (14.4) | ||
Type "help" for help. | ||
``` | ||
|
||
Hinweis: Sie können auch einen Benutzer mit den entsprechenden Datenbankberechtigungen verwenden. | ||
|
||
2. Wählen Sie die Datenbank `testdb` mit der folgenden Anweisung aus: | ||
|
||
```shell | ||
\c testdb; | ||
``` | ||
|
||
Wenn die Datenbank noch nicht erstellt wurde, führen Sie die folgende Anweisung aus: | ||
|
||
```shell | ||
CREATE DATABASE testdb; | ||
``` | ||
|
||
3. Verwenden Sie das Kommando `\dt`, um alle Tabellen in der Datenbank `testdb` aufzulisten: | ||
|
||
```shell | ||
\dt | ||
``` | ||
|
||
```shell | ||
Liste der Relationen | ||
Schema | Name | Type | Owner | ||
--------+----------------+-------+---------- | ||
public | mytable | table | postgres | ||
public | product | table | postgres | ||
public | test_date | table | postgres | ||
public | test_time | table | postgres | ||
public | test_timestamp | table | postgres | ||
public | week_day_sales | table | postgres | ||
(6 rows) | ||
``` | ||
|
||
4. Wenn Sie weitere Informationen zu den Tabellen anzeigen möchten, verwenden Sie das Kommando `\dt+`: | ||
|
||
```shell | ||
\dt+ | ||
``` | ||
|
||
```shell | ||
Liste der Relationen | ||
Schema | Name | Type | Owner | Persistence | Access method | Size | Beschreibung | ||
--------+----------------+-------+----------+-------------+---------------+------------+------------- | ||
public | mytable | table | postgres | permanent | heap | 16 kB | | ||
public | product | table | postgres | permanent | heap | 16 kB | | ||
public | test_date | table | postgres | permanent | heap | 8192 bytes | | ||
public | test_time | table | postgres | permanent | heap | 8192 bytes | | ||
public | test_timestamp | table | postgres | permanent | heap | 8192 bytes | | ||
public | week_day_sales | table | postgres | permanent | heap | 8192 bytes | | ||
(6 rows) | ||
``` | ||
|
||
Sie sehen, dass die Eingabe von `\dt+` zusätzliche Spalten wie `Persistence`, `Access method`, `Size` und `Beschreibung` enthält, zusätzlich zur Ausgabe von `\dt`. | ||
|
||
## Abfragen von Tabellen aus der Tabelle pg_tables | ||
|
||
Neben den Befehlen `\dt` und `\dt+` können Sie auch alle Tabellen in den aktuellen Daten aus der Tabelle `pg_tables` abfragen. | ||
|
||
Die Tabelle `pg_tables` ist eine integrierte Tabelle in PostgreSQL, die alle Tabellen in der Datenbank speichert. | ||
|
||
```shell | ||
SELECT * FROM pg_tables | ||
WHERE schemaname = 'public'; | ||
``` | ||
|
||
```shell | ||
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity | ||
------------+----------------+------------+------------+------------+----------+-------------+------------- | ||
public | test_date | postgres | | t | f | f | f | ||
public | test_time | postgres | | t | f | f | f | ||
public | test_timestamp | postgres | | t | f | f | f | ||
public | week_day_sales | postgres | | t | f | f | f | ||
public | mytable | postgres | | f | f | f | f | ||
public | product | postgres | | t | f | f | f | ||
(6 rows) | ||
``` | ||
|
||
## Fazit | ||
|
||
PostgreSQL bietet zwei Möglichkeiten, alle Tabellen in einer Datenbank aufzulisten: | ||
|
||
- Verwenden Sie `\dt` oder `\dt+` im psql-Tool, um alle Tabellen in der aktuellen Datenbank aufzulisten. | ||
- Abfragen Sie alle Tabellen aus der Tabelle `pg_tables`. | ||
|
||
In MySQL können Sie den Befehl `SHOW TABLES` verwenden, um Datenbanken aufzulisten. |
112 changes: 112 additions & 0 deletions
112
...urus-plugin-content-blog/list-tables-in-postgresql/list-tables-in-postgresql.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
--- | ||
slug: list-tables-in-postgresql | ||
title: "PostgreSQLのテーブル一覧の取得方法" | ||
description: この記事では、PostgreSQLデータベース内のテーブルを一覧表示するための2つの方法を紹介します。PostgreSQLはデータベース内のすべてのテーブルを一覧表示する2つの方法を提供しています。 | ||
authors: owen | ||
image: https://cdn.illacloud.com/illa-website/blog/list-tables-in-postgresql/cover.webp | ||
tags: [postgres, postgresql, database, list, tables, psql] | ||
date: 2024-01-04T10:00 | ||
--- | ||
|
||
この記事では、PostgreSQLデータベース内のテーブルを一覧表示するための2つの方法を紹介します。PostgreSQLはデータベース内のすべてのテーブルを一覧表示する2つの方法を提供しています: | ||
|
||
- `psql`ツールで`\dt`または`\dt+`を使用して現在のデータベースのすべてのテーブルを一覧表示します。 | ||
- `pg_tables`テーブルからすべてのテーブルをクエリします。 | ||
|
||
## \dtを使用してデータベース内のテーブルを一覧表示 | ||
|
||
この例では、`psql`ツールを使用してデータベースにログインし、データベース内のテーブルを一覧表示するプロセスを示しています。以下の手順に従ってください: | ||
|
||
1. postgresユーザーを使用してPostgreSQLサーバーにログインします: | ||
|
||
```shell | ||
[~] psql -U postgres | ||
psql (14.4) | ||
Type "help" for help. | ||
``` | ||
|
||
注意:適切なデータベース権限を持つ任意のユーザーも使用できます。 | ||
|
||
2. 以下のステートメントで`testdb`データベースを選択します: | ||
|
||
```shell | ||
\c testdb; | ||
``` | ||
|
||
データベースがまだ作成されていない場合は、次のステートメントを実行します: | ||
|
||
```shell | ||
CREATE DATABASE testdb; | ||
``` | ||
|
||
3. `\dt`コマンドを使用して`testdb`データベースのすべてのテーブルを一覧表示します: | ||
|
||
```shell | ||
\dt | ||
``` | ||
|
||
```shell | ||
リレーションの一覧 | ||
Schema | Name | Type | Owner | ||
--------+----------------+-------+---------- | ||
public | mytable | table | postgres | ||
public | product | table | postgres | ||
public | test_date | table | postgres | ||
public | test_time | table | postgres | ||
public | test_timestamp | table | postgres | ||
public | week_day_sales | table | postgres | ||
(6 rows) | ||
``` | ||
|
||
4. テーブルに関する詳細情報を表示したい場合は、`\dt+`コマンドを使用します: | ||
|
||
```shell | ||
\dt+ | ||
``` | ||
|
||
```shell | ||
リレーションの一覧 | ||
Schema | Name | Type | Owner | Persistence | Access method | Size | Description | ||
--------+----------------+-------+----------+-------------+---------------+------------+------------- | ||
public | mytable | table | postgres | permanent | heap | 16 kB | | ||
public | product | table | postgres | permanent | heap | 16 kB | | ||
public | test_date | table | postgres | permanent | heap | 8192 bytes | | ||
public | test_time | table | postgres | permanent | heap | 8192 bytes | | ||
public | test_timestamp | table | postgres | permanent | heap | 8192 bytes | | ||
public | week_day_sales | table | postgres | permanent | heap | 8192 bytes | | ||
(6 rows) | ||
``` | ||
|
||
`\dt+`の入力には、`\dt`の出力に加えて`Persistence`、`Access method`、`Size`、および`Description`などの列が含まれています。 | ||
|
||
## pg_tablesテーブルからテーブルをクエリ | ||
|
||
`\dt`および`\dt+`コマンドに加えて、`pg_tables`テーブルから現在のデータベース内のすべてのテーブルをクエリすることもできます。 | ||
|
||
`pg_tables`テーブルは、PostgreSQLの組み込みテーブルで、データベース内のすべてのテーブルを格納しています。 | ||
|
||
```shell | ||
SELECT * FROM pg_tables | ||
WHERE schemaname = 'public'; | ||
``` | ||
|
||
```shell | ||
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers | rowsecurity | ||
------------+----------------+------------+------------+------------+----------+-------------+------------- | ||
public | test_date | postgres | | t | f | f | f | ||
public | test_time | postgres | | t | f | f | f | ||
public | test_timestamp | postgres | | t | f | f | f | ||
public | week_day_sales | postgres | | t | f | f | f | ||
public | mytable | postgres | | f | f | f | f | ||
public | product | postgres | | t | f | f | f | ||
(6 rows) | ||
``` | ||
|
||
## 結論 | ||
|
||
PostgreSQLはデータベース内のすべてのテーブルを一覧表示するために2つの方法を提供しています: | ||
|
||
- `psql`ツールで`\dt`または`\dt+`を使用して現在のデータベースのすべてのテーブルを一覧表示します。 | ||
- `pg_tables`テーブルからすべてのテーブルをクエリします。 | ||
|
||
MySQLでは、データベースを一覧表示するために`SHOW TABLES`コマンドを使用できます。 |
Oops, something went wrong.