troubleshooting Question

Postgres Foreign Keys

Avatar of Richard2048
Richard2048 asked on
Web DevelopmentPostgreSQL
3 Comments1 Solution577 ViewsLast Modified:
I wish to write a query that will return a list of foreign keys and the table to which they pertain.
For example:
- Given a table of 'customers' and a table of 'accounts', in which each customer can have 1 or more accounts
- The FK in accounts is a customer_id

How would I write a query to list the foreign key(s) in the accounts table along with the table to which said foreign key relates.
For exampe:
I want to query the 'accounts' table, so as to retrieve the customer_id as the FK and the customers table as the table linked to this FK.

Any ideas?

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros