Re: Deleting orphan records - Mailing list pgsql-general

From Nigel J. Andrews
Subject Re: Deleting orphan records
Date
Msg-id Pine.LNX.4.21.0302060730470.20150-100000@ponder.fairway2k.co.uk
Whole thread Raw
In response to Re: Deleting orphan records  (John Smith <john_smith_45678@yahoo.com>)
Responses Re: Deleting orphan records
List pgsql-general
On Wed, 5 Feb 2003, John Smith wrote:

>
> I was referring to parent records with no children ;).
> John
>  Chris Travers <chris@travelamericas.com> wrote:Does ON DELETE CASCADE not work for you? Other than that you would
havedo do outer join acrobatics ;-) Best Regards;Chris Travers----- Original Message ----- From: John Smith To:
pgsql-general@postgresql.orgSent: Wednesday, February 05, 2003 12:55 PMSubject: [GENERAL] Deleting orphan records 
> Does anybody have a method for deleting orphan (unreferenced) records? Is it possible to set up some sort of
constraintor trigger (that performs well when lots of records are deleted ;) )?  
>

I'm was sure I'd seen mention of using an extra table in the delete statement
in the docs. However, I can't see it in 7.4dev. Going by that short description
though the following might be possible:

DELETE FROM table1
WHERE
  NOT EXISTS ( SELECT FROM table2 WHERE table2.forkeycol = table1.forkeycol )

According the the docs the reader is directed to the SELECT page for details of
the WHERE clause and the above would be valid for a select.

--
Nigel J. Andrews


pgsql-general by date:

Previous
From: John Smith
Date:
Subject: COPY with fk's slow
Next
From: Francois Suter
Date:
Subject: Re: PostgreSQL Mailing Lists in Italian?