From: wieck@debis.com
To: Matthew Hagerty <matthew@venux.net>
Cc: pgsql-sql@postgreSQL.org
Subject: Re: [SQL] Finding missing records...
Date: Fri, 25 Feb 2000 17:11:35 +0100 (CET)
Message-ID: <m12ONL6-0003kgC@orion.SAPserv.Hamburg.dsh.de> (raw)
In-Reply-To: <4.2.2.20000225105014.00ba6bf0@mail.venux.net>
> Greetings,
>
> I have two tables that maintain a 1:1 relationship via an int based primary
> key. A record in the primary table should never exist without an
> associated record in the secondary table, however somehow this has
> happened. Can someone demonstrate a query that would show all records in
> the primary table that do not have associated records in the secondary table?
SELECT att_pk FROM tab_pk WHERE NOT EXISTS
(SELECT att_fk FROM tab_fk WHERE att_fk = att_pk);
This is the SQL3 referential definition of PENDANT. It'll not
be in the FOREIGN KEY support of 7.0, but we'll discuss if we
implement it for 7.1 (even if it will be damned slooooow if
done on every delete/update to an FK table).
Jan
--
#======================================================================#
# It's easier to get forgiveness for being wrong than for being right. #
# Let's break this rule - forgive me. #
#========================================= wieck@debis.com (Jan Wieck) #
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: wieck@debis.com, matthew@venux.net
Subject: Re: [SQL] Finding missing records...
In-Reply-To: <m12ONL6-0003kgC@orion.SAPserv.Hamburg.dsh.de>
References: <4.2.2.20000225105014.00ba6bf0@mail.venux.net> <m12ONL6-0003kgC@orion.SAPserv.Hamburg.dsh.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox