在 PostgreSQL 中,擷取與索引對應的資料列與 MySQL 的 SHOW INDEXES 指令不同。
獲取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' and t.relname like 'test%';
此查詢檢索表和索引名稱以及關聯的列名稱。為了獲得更多見解,可以修改查詢以聚合列名稱:
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' and t.relname like 'test%' group by t.relname, i.relname order by t.relname, i.relname;
以上是如何檢索與 PostgreSQL 中的索引關聯的欄位?的詳細內容。更多資訊請關注PHP中文網其他相關文章!