Re: Delete all records NOT referenced by Foreign Keys

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: "D(dot) Dante Lorenso" <dante(at)lorenso(dot)com>
Cc: Bruno Wolff III <bruno(at)wolff(dot)to>, pgsql-general(at)postgresql(dot)org
Subject: Re: Delete all records NOT referenced by Foreign Keys
Date: 2003-12-14 06:17:24
Message-ID: 20031214061724.GD30016@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message D. Dante Lorenso 2003-12-14 07:14:28 Re: Delete all records NOT referenced by Foreign Keys
Previous Message Keith C. Perry 2003-12-14 05:43:20 Re: tablespaces in 7.5?