Postgres: Find table foreign keys (Faster alternative)

Posted by Najera on Stack Overflow See other posts from Stack Overflow or by Najera
Published on 2012-11-15T15:15:59Z Indexed on 2012/11/15 17:00 UTC
Read the original article Hit count: 134

Filed under:
|
|

Is there faster alternative to this:

Take almost 1 minute in our server.

SELECT
    tc.constraint_name, tc.table_name, kcu.column_name, 
    ccu.table_name AS foreign_table_name,
    ccu.column_name AS foreign_column_name 
FROM 
    information_schema.table_constraints AS tc 
    JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name
    JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name
WHERE constraint_type = 'FOREIGN KEY' AND tc.table_name='mytable';

Maybe using pg_class metadata?, thanks.

© Stack Overflow or respective owner

Related posts about sql

Related posts about postgresql