Re: Feature Request: Better handling of foreign keys in DELETE statements - Mailing list pgsql-general

From Hannes Erven
Subject Re: Feature Request: Better handling of foreign keys in DELETE statements
Date
Msg-id 4EEFB0BC.4060400@erven.at
Whole thread Raw
In response to Feature Request: Better handling of foreign keys in DELETE statements  (Daniel Migowski <dmigowski@ikoffice.de>)
List 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

pgsql-general by date:

Previous
From: Havasvölgyi Ottó
Date:
Subject: Re: fsync on ext4 does not work
Next
From: Adrian Klaver
Date:
Subject: Re: Changing Passwords as Encrypted not Clear-Text