我获得了列名,位置数据类型和非空?用这个查询:
SELECT column_name,data_type,ordinal_position,is_nullable FROM information_schema."columns"WHERE "table_name"='table-name'
但是,我需要评论!
这是针对 system catalog的查询,应该会获取所需的一切(免费提供奖金主键字段).SELECT disTINCT a.attnum as num,a.attname as name,format_type(a.atttypID,a.atttypmod) as typ,a.attnotnull as notnull,com.description as comment,coalesce(i.indisprimary,false) as primary_key,def.adsrc as defaultFROM pg_attribute a JOIN pg_class pgc ON pgc.oID = a.attrelIDleft JOIN pg_index i ON (pgc.oID = i.indrelID AND i.indkey[0] = a.attnum)left JOIN pg_description com on (pgc.oID = com.objoID AND a.attnum = com.obJsubID)left JOIN pg_attrdef def ON (a.attrelID = def.adrelID AND a.attnum = def.adnum)WHERE a.attnum > 0 AND pgc.oID = a.attrelIDAND pg_table_is_visible(pgc.oID)AND NOT a.attisdroppedAND pgc.relname = 'table_name' -- Your table name hereORDER BY a.attnum;
这会返回以下结果:
num | name | typ | notnull | comment | primary_key -----+-------------+-----------------------------+---------+---------------------+------------- 1 | ID | integer | t | a primary key thing | t 2 | ref | text | f | | f 3 | created | timestamp without time zone | t | | f 4 | modifIEd | timestamp without time zone | t | | f 5 | name | text | t | | f
> num:列号> name:列名> typ:数据类型> notnull:列定义为NOT NulL> comment:为列定义的任何COMMENT> primary_key:列定义为PRIMARY KEY> default:用于默认值的命令
总结以上是内存溢出为你收集整理的如何使用PostgreSQL从表名中获取列属性查询?全部内容,希望文章能够帮你解决如何使用PostgreSQL从表名中获取列属性查询?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)