Re: Feature Request: Better handling of foreign keys in DELETE statements

From: Hannes Erven <hannes(at)erven(dot)at>
To: pgsql-general(at)postgresql(dot)org
Cc: dmigowski(at)ikoffice(dot)de
Subject: Re: Feature Request: Better handling of foreign keys in DELETE statements
Date: 2011-12-19 21:46:36
Message-ID: 4EEFB0BC.4060400@erven.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Daniel,

> Now I wanted to delete about 10 million addresses (that are not
> referenced anymore from anywhere), and have a statement like:

What about:

DELETE FROM address
WHERE id IN (
SELECT id FROM address
EXCEPT
(
SELECT address_id FROM tab1
UNION ALL
SELECT address_id FROM tab2
UNION ALL
...
)
)
?

You could also easily restrict that query to multiple ranges of
adress.ids to control memory usage and transaction duration.

-hannes

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2011-12-19 22:59:02 Re: Changing Passwords as Encrypted not Clear-Text
Previous Message Havasvölgyi Ottó 2011-12-19 21:34:02 Re: fsync on ext4 does not work