Visualizar todas as foreign keys de um banco postgresql

Posted . Visible to the public.
SELECT
    c.conname nomeForeignKey,
    c.conrelid::pg_catalog.regclass tabelaOrigem,
    pg_catalog.pg_get_constraintdef(c.oid, TRUE) AS definicaoForeignKey
FROM pg_catalog.pg_constraint c
    JOIN pg_catalog.pg_class r ON r.oid = c.confrelid
    JOIN pg_catalog.pg_namespace n ON n.oid = r.relnamespace
    WHERE n.nspname = 'public' AND c.contype = 'f'
ORDER BY c.conrelid, r.relname, c.conname;
Bruno Vieira
Posted by Bruno Vieira to ZeroGlosa (2013-11-07 20:10)