スキーマの名前を調べる
sch で始まるスキーマ
SELECT schema_name FROM information_schema.schemata where schema_name LIKE 'sch%';
テーブルの名前を調べる
grp で始まるテーブル
select table_name from information_schema.tables where table_name LIKE 'grp%';
grp で始まるテーブルの数
select count(*) from information_schema.tables where table_name LIKE 'grp%';
コラムの名前を調べる
SELECT column_name FROM information_schema.columns WHERE table_name = 'cities';
実行結果
city=# SELECT column_name FROM information_schema.columns WHERE table_name = 'cities';
column_name
-------------
population
date_mod
id
name
(4 rows)
コラムの名前 と Not Null かを調べる
SELECT column_name, is_nullable FROM information_schema.columns WHERE table_name = 'cities';
実行結果
city=# SELECT column_name, is_nullable FROM information_schema.columns WHERE table_name = 'cities';
column_name | is_nullable
-------------+-------------
population | YES
date_mod | YES
id | NO
name | YES
(4 rows)
コラム名を与えてテーブル名を調べる
select table_name from information_schema.columns WHERE column_name = 'population';