开发者社区> 问答> 正文

hologres 查询某个schema下所有的主键信息

已解决

hologres 查询某个schema下所有的主键信息

展开
收起
提个问题 2024-06-15 13:15:51 50 0
1 条回答
写回答
取消 提交回答
  • 开发者社区问答官方账号
    官方回答
    采纳回答
    查询某个schema下所有的主键信息请参考:
    SELECT result.TABLE_SCHEM schem, result.TABLE_NAME 表名, result.COLUMN_NAME 主键列, result.KEY_SEQ FROM (SELECT n.nspname AS TABLE_SCHEM, ct.relname AS TABLE_NAME, a.attname AS COLUMN_NAME, (information_schema._pg_expandarray(i.indkey)).n AS KEY_SEQ, ci.relname AS PK_NAME, information_schema._pg_expandarray(i.indkey) AS KEYS, a.attnum AS A_ATTNUM FROM pg_catalog.pg_class ct JOIN pg_catalog.pg_attribute a ON (ct.oid = a.attrelid) JOIN pg_catalog.pg_namespace n ON (ct.relnamespace = n.oid) JOIN pg_catalog.pg_index i ON (a.attrelid = i.indrelid) JOIN pg_catalog.pg_class ci ON (ci.oid = i.indexrelid) WHERE true AND n.nspname = 'public' AND i.indisprimary) result where result.A_ATTNUM = (result.KEYS).x ORDER BY result.table_name, result.pk_name, result.key_seq;
    2024-06-15 13:15:52
    赞同 1 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
实时数仓Workshop(广州站)- 李佳林 立即下载
阿里云实时数仓Hologres技术揭秘2.0 立即下载
实时数仓Hologres技术实战一本通2.0版(下) 立即下载