擷取 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中文網其他相關文章!