dak ブログ

python、rubyなどのプログラミング、MySQL、サーバーの設定などの備忘録。レゴの写真も。

PostgreSQL でテーブル情報などを確認する方法

2025-02-21 23:09:03 | PostgreSQL

PostgreSQL でテーブル情報などを確認する方法のメモ。

データベース一覧

# \list
                                                     List of databases
       Name       |  Owner   | Encoding | Locale Provider | Collate |  Ctype  | Locale | ICU Rules |   Access privileges
------------------+----------+----------+-----------------+---------+---------+--------+-----------+-----------------------
 postgres         | postgres | UTF8     | libc            | C.UTF-8 | C.UTF-8 |        |           |
 template0        | postgres | UTF8     | libc            | C.UTF-8 | C.UTF-8 |        |           | =c/postgres          +
                  |          |          |                 |         |         |        |           | postgres=CTc/postgres
 template1        | postgres | UTF8     | libc            | C.UTF-8 | C.UTF-8 |        |           | =c/postgres          +
                  |          |          |                 |         |         |        |           | postgres=CTc/postgres
 test1            | postgres | UTF8     | libc            | C.UTF-8 | C.UTF-8 |        |           |
 test2            | postgres | UTF8     | libc            | C.UTF-8 | C.UTF-8 |        |           |

データベースに接続

# \connect test1

テーブル定義

# \d test1
                      Table "public.test1"
 Column |         Type          | Collation | Nullable | Default
--------+-----------------------+-----------+----------+---------
 id     | character varying(32) |           | not null |
 name   | character varying(32) |           | not null |
Indexes:
    "test1_pkey" PRIMARY KEY, btree (id)

select

# select * from test1;
   id   |   name
--------+----------
 id_001 | name_001
 id_002 | name_002
 id_003 | name_003
 id_004 | name_004
 id_005 | name_005

検索結果を縦方向に表示

# \x
Expanded display is on.

# select * from test1;
-[ RECORD 1 ]--
id   | id_001
name | name_001
-[ RECORD 2 ]--
id   | id_002
name | name_002
-[ RECORD 3 ]--
id   | id_003
name | name_003
-[ RECORD 4 ]--
id   | id_004
name | name_004
-[ RECORD 5 ]--
id   | id_005
name | name_005

この記事についてブログを書く
« PostgreSQL で実行中のクエリ... | トップ |   

PostgreSQL」カテゴリの最新記事