Postgresでテーブル定義を確認(\d)

Postgresのpsqlコンソールでテーブル定義を確認するには、\d コマンドを使います。

\d のあとにテーブル名を指定します。

postgres=# \d users;
                                              Table "public.users"
         Column         |            Type             | Collation | Nullable |              Default
------------------------+-----------------------------+-----------+----------+-----------------------------------
 id                     | bigint                      |           | not null | nextval('users_id_seq'::regclass)
 email                  | character varying           |           | not null | ''::character varying
 encrypted_password     | character varying           |           | not null | ''::character varying
 reset_password_token   | character varying           |           |          |
 reset_password_sent_at | timestamp without time zone |           |          |
 remember_created_at    | timestamp without time zone |           |          |
 sign_in_count          | integer                     |           | not null | 0
 current_sign_in_at     | timestamp without time zone |           |          |
 last_sign_in_at        | timestamp without time zone |           |          |
 current_sign_in_ip     | inet                        |           |          |
 last_sign_in_ip        | inet                        |           |          |
 confirmation_token     | character varying           |           |          |
 confirmed_at           | timestamp without time zone |           |          |
 confirmation_sent_at   | timestamp without time zone |           |          |
 unconfirmed_email      | character varying           |           |          |
 failed_attempts        | integer                     |           | not null | 0
 unlock_token           | character varying           |           |          |
 locked_at              | timestamp without time zone |           |          |
 created_at             | timestamp without time zone |           | not null |
 updated_at             | timestamp without time zone |           | not null |
 provider               | character varying           |           |          |
 uid                    | character varying           |           |          |
 username               | character varying           |           |          |
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)
    "index_users_on_confirmation_token" UNIQUE, btree (confirmation_token)
    "index_users_on_email" UNIQUE, btree (email)
    "index_users_on_reset_password_token" UNIQUE, btree (reset_password_token)
    "index_users_on_unlock_token" UNIQUE, btree (unlock_token)

以上です。

 

 

タイトルとURLをコピーしました