Re: fields and foreign keys

Поиск
Список
Период
Сортировка
От Michael Fuhr
Тема Re: fields and foreign keys
Дата
Msg-id 20050624141935.GA45212@winnie.fuhr.org
обсуждение исходный текст
Ответ на Re: fields and foreign keys  ("mrix" <gmarik@gmail.com>)
Список 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/

В списке pgsql-general по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: PostgreSQL Certification
Следующее
От: Martijn van Oosterhout
Дата:
Сообщение: Re: Non-unique index performance