0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

PostgreSQL カラムの情報一覧を取得する方法

Last updated at Posted at 2022-05-24

はじめに

PostgreSQLを学び始めました。
KaggleのデータをPostgreSQLに入れて、いろいろ実験しています。

まずは、どのようなデータが格納されているのか、チェックしたかったのでスキーマについて調べてみました。

スキーマとは?

スキーマはテーブルに紐付いているスコープのような概念です。
ディレクトリを設けるようにデータ間に仕切りを設けることで、命名の干渉や、参照できる権限を管理することができます。

ユーザーが作成するテーブルには、指定をしなければ、デフォルトでpublicというスキーマが定義されます。

PostgreSQL 13.1文書 5.9. スキーマ

カラムの情報一覧を表示

どんなテーブルがあり、どのような情報を格納しているのか一覧を出力する

以下のSQLを入力するとanimeというテーブルが持っている情報の一覧が取得できます。

SELECT
    *
FROM
    information_schema.columns
WHERE
    table_schema = 'public'
    AND table_name = 'anime'
;

プライマリーキーの一覧を取得

SELECT
    *
FROM
    information_schema.table_constraints
WHERE
    constraint_type = 'PRIMARY KEY'
;

参考

PostgreSQL 13.1文書
PostgreSQLのシステムテーブル入門 (暗記用のSQL集) - 主に言語とシステム開発に関して

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?