Re: fields and foreign keys

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: mrix <gmarik(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: fields and foreign keys
Date: 2005-06-24 14:19:35
Message-ID: 20050624141935.GA45212@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 23, 2005 at 10:11:15PM -0700, mrix wrote:
>
> But I've already tried this approach, and it's not quite i need.
> Because as i understand foreign keys are built on indexes, so i get
> *index* and corresponding foreign key definition.
> Well then i have to find out what filed this index "belongs to"
> (assuming 1 field - 1 index)

The query I posted shows the relation (table) that contains the
foreign key constraint, the constraint name (not an index name),
and the constraint definition, which includes the names of the
referring column(s) and the referred-to table and column(s). For
example:

CREATE TABLE foo (id integer PRIMARY KEY);
CREATE TABLE bar (fooid integer NOT NULL REFERENCES foo);

SELECT conrelid::regclass, conname, pg_get_constraintdef(oid)
FROM pg_constraint
WHERE contype = 'f';
conrelid | conname | pg_get_constraintdef
----------+----------------+----------------------------------------
bar | bar_fooid_fkey | FOREIGN KEY (fooid) REFERENCES foo(id)
(1 row)

If this isn't what you're looking for, then please post an example
that shows what you're trying to do. That is, something like "given
the following table definitions, I'm looking for a query that will
give me this output...."

What problem are you trying to solve?

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Martijn van Oosterhout 2005-06-24 14:39:28 Re: Non-unique index performance
Previous Message Peter Eisentraut 2005-06-24 14:18:48 Re: PostgreSQL Certification