How to get column attributes query from table name using PostgreSQL?

后端 未结 3 1365
离开以前
离开以前 2020-12-13 15:49

I have a project and I need a query to get all attributes of the columns (Column Name, Position, Data Type, Not Null? and Comments) all this using table name.

I ach

3条回答
  •  無奈伤痛
    2020-12-13 16:30

    I think you can use this:

    select ordinal_position AS num, column_name as name, data_type as typ, character_maximum_length as lenth, 
    is_nullable as nullable, column_default as default
    from INFORMATION_SCHEMA.COLUMNS
    WHERE table_catalog='DatabaseName' AND table_name='TableName'
    

提交回复
热议问题