sql >> Databasteknik >  >> RDS >> PostgreSQL

Lista alla indexnamn, kolumnnamn och dess tabellnamn för en PostgreSQL-databas

Detta kommer att mata ut alla index med detaljer (extraherat från mina vydefinitioner):

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;

Lägg eventuellt till en extra sammanfogning i slutet för att trimma namnområdena:

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. mysqli_stmt::bind_result():Antal bindningsvariabler matchar inte antalet fält i förberedd programsats

  2. PDOException SQLSTATE[HY000] [2002] Ingen sådan fil eller katalog

  3. SQL Server-autentisering vs. Windows-autentisering:Vilken ska användas och när

  4. Varför rapporterar MySQL ett syntaxfel vid FULL OUTER JOIN?