sql >> データベース >  >> RDS >> PostgreSQL

PostgreSQLデータベースのすべてのインデックス名、列名、およびそのテーブル名を一覧表示します

    これにより、すべてのインデックスが詳細とともに出力されます(ビュー定義から抽出):

    SELECT i.relname as indname,
           i.relowner as indowner,
           idx.indrelid::regclass,
           am.amname as indam,
           idx.indkey,
           ARRAY(
           SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
           FROM generate_subscripts(idx.indkey, 1) as k
           ORDER BY k
           ) as indkey_names,
           idx.indexprs IS NOT NULL as indexprs,
           idx.indpred IS NOT NULL as indpred
    FROM   pg_index as idx
    JOIN   pg_class as i
    ON     i.oid = idx.indexrelid
    JOIN   pg_am as am
    ON     i.relam = am.oid;
    

    必要に応じて、名前名をトリミングするために、最後に結合を追加します。

    SELECT i.relname as indname,
           i.relowner as indowner,
           idx.indrelid::regclass,
           am.amname as indam,
           idx.indkey,
           ARRAY(
           SELECT pg_get_indexdef(idx.indexrelid, k + 1, true)
           FROM generate_subscripts(idx.indkey, 1) as k
           ORDER BY k
           ) as indkey_names,
           idx.indexprs IS NOT NULL as indexprs,
           idx.indpred IS NOT NULL as indpred
    FROM   pg_index as idx
    JOIN   pg_class as i
    ON     i.oid = idx.indexrelid
    JOIN   pg_am as am
    ON     i.relam = am.oid
    JOIN   pg_namespace as ns
    ON     ns.oid = i.relnamespace
    AND    ns.nspname = ANY(current_schemas(false));
    


    1. jdbctemplateを介したSQL挿入からのID

    2. Oracleの日付から文字列への変換

    3. IRIWorkbenchでのインクリメンタルデータレプリケーション

    4. PostgreSQL8.3以降の全文検索