GaussDB(DWS) 快速查到一张表的列信息
【摘要】 GaussDB(DWS) 快速查到一张表的列信息
information_schema下的视图在数据库中对象较多时返回结果很慢,可以通过以下sql快速查询到一张或几张表的列信息:
select /*+ nestloop(a c)*/ c.column_name, c.data_type, c.ordinal_position, pgd.description, pp.partkey, c.is_nullable, c.column_default, c.character_maximum_length, c.numeric_precision, c.numeric_scale, c.datetime_precision, c.interval_type, c.udt_name from information_schema.columns as c left join pg_namespace sp on sp.nspname = c.table_schema left join pg_class cla on cla.relname = c.table_name and cla.relnamespace = sp.oid left join pg_catalog.pg_partition pp on (pp.parentid = cla.oid and pp.parttype = 'r') left join pg_catalog.pg_description pgd on (pgd.objoid=cla.oid and pgd.objsubid = c.ordinal_position) where c.table_name in ('t1') and c.table_schema = 'public';
使用时可以将table_name和table_schema替换成需要查询的模式名和表名。
查询结果如下:
column_name | data_type | ordinal_position | description | partkey | is_nullable | column_default | character_maximum_length | numeric_precision | numeric_scale | datetime_precision | interval_type | udt_name -------------+-----------+------------------+---------------+---------+-------------+----------------+--------------------------+-------------------+---------------+--------------------+---------------+---------- b | integer | 2 | second column | | YES | | | 32 | 0 | | | int4 a | integer | 1 | first column | | YES | | | 32 | 0 | | | int4 (2 rows)
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)