Re: Delete all records NOT referenced by Foreign Keys - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: Delete all records NOT referenced by Foreign Keys
Date
Msg-id 20031214061724.GD30016@svana.org
Whole thread Raw
In response to Re: Delete all records NOT referenced by Foreign Keys  ("D. Dante Lorenso" <dante@lorenso.com>)
Responses Re: Delete all records NOT referenced by Foreign Keys  ("D. Dante Lorenso" <dante@lorenso.com>)
List pgsql-general
On Sat, Dec 13, 2003 at 09:48:16PM -0600, D. Dante Lorenso wrote:
> This is something very ugly indeed and is what I'll have to resort to unless
> I can find something cleaner.  Ideally, I would be able to run this cleanup
> on a subset of the table data after an insert into the table.  I would like
> the query to be fast, though.

What about just:

delete from a where a.id not in (select id from b);

or the equivalent exists query.
--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> (... have gone from d-i being barely usable even by its developers
> anywhere, to being about 20% done. Sweet. And the last 80% usually takes
> 20% of the time, too, right?) -- Anthony Towns, debian-devel-announce

Attachment

pgsql-general by date:

Previous
From: "Keith C. Perry"
Date:
Subject: Re: tablespaces in 7.5?
Next
From: "D. Dante Lorenso"
Date:
Subject: Re: Delete all records NOT referenced by Foreign Keys