カラム一覧出力SQL
select --c.table_schema,c.table_name, c.column_name,c.ordinal_position as "position" ,c.data_type,c.character_maximum_length as "length" ,c.numeric_precision as "precision" ,c.numeric_scale as "scale" ,c.is_generated ,c.column_default from information_schema.columns c where c.table_name='kokudo_address_chome' and c.table_schema = 'sooni' order by c.ordinal_position ;
カラム一覧出力例
is_generatedにて通常の列(NEVER)もしくは生成列(ALWAYS)なのか判定できます。
column_name | position | data_type | length | precision | scale | is_generated | column_default
----------------------+----------+--------------------------+--------+-----------+-------+--------------+-------------------
prefectures_code | 1 | character varying | 2 | | | NEVER |
prefectures_name | 2 | character varying | 32 | | | NEVER |
city_code | 3 | character varying | 5 | | | NEVER |
city_name | 4 | character varying | 64 | | | NEVER |
oaza_town_chome_code | 5 | character varying | 12 | | | NEVER |
oaza_town_chome_name | 6 | character varying | 32 | | | NEVER |
latitude | 7 | numeric | | 11 | 8 | NEVER |
longitude | 8 | numeric | | 11 | 8 | NEVER |
document_code | 9 | integer | | 32 | 0 | NEVER |
chome_kubun_code | 10 | integer | | 32 | 0 | NEVER |
creatation_date | 11 | timestamp with time zone | | | | NEVER | CURRENT_TIMESTAMP
(11 行)
myposdb=#