在 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中文网其他相关文章!