Re: foreign keys not working

From: "Joel Burton" <joel(at)joelburton(dot)com>
To: "Jeff Wright" <Jeff(dot)Wright(at)OMNIChannels(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: foreign keys not working
Date: 2002-05-15 13:49:58
Message-ID: JGEPJNMCKODMDHGOBKDNAEFLCOAA.joel@joelburton.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> -----Original Message-----
> From: pgsql-general-owner(at)postgresql(dot)org
> [mailto:pgsql-general-owner(at)postgresql(dot)org]On Behalf Of Jeff Wright
> Sent: Tuesday, May 14, 2002 12:22 PM
> To: 'pgsql-general(at)postgresql(dot)org'
> Subject: [GENERAL] foreign keys not working
>
> I'm trying to set up some fk's on some tables and the sql works with no
> errors but the schema display for the table doesn't show the
> fk's. Is there
> something I need to do to enable fk functionality?

Jeff --

Unfortunately, you don't see the FK's indicated on the schema displays in
psql. In the latest versions of PG, you'll see Triggers listed (which
referential integrity is, a trigger), but that still doesn't tell you which
field is the foreign key to which table.

You can see this information by hacking into the referential integrity
tables yourself.

Try this view:

CREATE VIEW dev_ri
AS
SELECT t.oid as trigoid,
c.relname as trig_tbl,
t.tgfoid,
f.proname as trigfunc,
t.tgenabled,
t.tgconstrname,
c2.relname as const_tbl,
t.tgdeferrable,
t.tginitdeferred
FROM pg_trigger t,
pg_class c,
pg_class c2,
pg_proc f
WHERE t.tgrelid=c.oid
AND t.tgconstrrelid=c2.oid
AND tgfoid=f.oid
AND tgname ~ '^RI_'
ORDER BY t.oid;

This will show you all fk's in your database.

Details on this can be found at
http://techdocs.postgresql.org/techdocs/hackingreferentialintegrity.php

HTH.

Joel BURTON | joel(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Knowledge Management & Technology Consultant

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Evgeniy Strokin 2002-05-15 13:58:18 XML from postgreSQL tables
Previous Message Darko Prenosil 2002-05-15 12:46:02 Re: [Fwd: [JDBC] Problem: upgrade from 7.1.3 to 7.2.1 ( database encodewith ENC_TW)]