检索 PostgreSQL 中的索引列
要获取 PostgreSQL 中索引的列,您可以使用以下查询:
SELECT t.relname AS table_name, i.relname AS index_name, a.attname AS column_name FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r';
要按索引进一步聚合结果,请使用此查询:
SELECT t.relname AS table_name, i.relname AS index_name, array_to_string(array_agg(a.attname), ', ') AS column_names FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND a.attnum = ANY(ix.indkey) AND t.relkind = 'r' GROUP BY t.relname, i.relname;
PostgreSQL 元信息提取的其他资源:
以上是如何在 PostgreSQL 中检索索引列?的详细内容。更多信息请关注PHP中文网其他相关文章!