Looks like my original post did not go through...posting again...

I'm writing software which will be used to walk through a large/complex database and map out primary keys, differentiating between local and foreign keys. Then it produces an SVG image showing dependencies between tables and naming some XML files which are related to each table...the goal being to graphically represent required data load orders (eventually it will also produce a script to load the XML files). When a constraint has several columns listed I'm having an issue in naming which specific column of the foreign table is used with a specific column in the local table. I'm getting all columns of the foreign table as a row in combination with a single column of the local table (there should be only one local column mapped to one foreign column).

Here is the starting query (PostgreSQL 9.4):
Code:
SELECT
    tc.table_name AS local_table,
    kcu.column_name AS key_column, 
    ccu.table_name AS fk_table,
    ccu.column_name AS fk_table_column
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'
ORDER BY local_table, fk_table, key_column;
In one special case where the foreign table column matches the name of the local table column I can work around this with:
Code:
    AND kcu.column_name = ccu.column_name
In PostgreSQL, is there a way to do the equivalent of this workaround when the key column of the original table uses a different name than the foreign table column? I am not a SQL guru and I have not yet found a way to do this efficiently.