PostgreSQL でのインデックスに対応する列の取得は、MySQL の SHOW INDEXES コマンドとは異なります。
取得するにはPostgreSQL で必要な情報を取得するには、以下を利用します。 query:
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 中国語 Web サイトの他の関連記事を参照してください。