Search Postgresql Archives

Re: fields and foreign keys

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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/

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux