3
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 1 year has passed since last update.

【SQL】テーブル名一覧/カラム名一覧を取得する

Posted at

あまり使用頻度は高くない。けど、いざという時に出てこないSQL
PostgreSQLにて使用していました。

特定スキームにあるテーブル名一覧を取得

select
  tablename
from
  pg_tables
where
  schemaname = '何かあれば記載'
order by
  tablename
;

特定のカラム名を持つテーブル一覧を取得

select table_name, column_name from information_schema.columns where column_name ='カラム名';

特定テーブルにあるカラム名一覧を取得

SELECT column_name FROM information_schema.columns WHERE table_name = 'テーブル名' ORDER BY table_name,ordinal_position;

日付カラムを任意の単位にする

  date_trunc('month', テーブルA.日付カラム)

→2022-03-16だとしたら「2022-03-01」になる

3
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
3
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?