Re: Delete all records NOT referenced by Foreign Keys

From: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
To: "D(dot) Dante Lorenso" <dante(at)lorenso(dot)com>
Cc: Martijn van Oosterhout <kleptog(at)svana(dot)org>, 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 08:38:46
Message-ID: 20031214002702.X31833@megazone.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Sun, 14 Dec 2003, D. Dante Lorenso wrote:

> PG already can block a delete when it knows that foreign key exists, so
> why can't I perform a query that says...
>
> DELETE FROM tablename
> WHERE FOREIGN_KEY_EXISTS(oid) IS FALSE;

That's fairly different from the checks that are performed for the foreign
keys which happen after the action has happened and errors to prevent the
action from being visible. The where clause happens long before that. If
the above has to check each referencing table for matching rows for each
row in tablename, I'd also expect it to perform poorly.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Stark 2003-12-14 08:53:26 Re: Delete all records NOT referenced by Foreign Keys
Previous Message Mike Coleman 2003-12-14 07:29:46 Re: make error Mac OS X (ar: illegal option -- s)