From: | Arjen Nienhuis <a(dot)g(dot)nienhuis(at)gmail(dot)com> |
---|---|
To: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | How to defer ON DELETE CASCADE |
Date: | 2010-09-01 16:03:57 |
Message-ID: | AANLkTimaxSOPXZaotsAoegVqVL62CDE9hmrvvDY3mL+E@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi,
If I create a DEFERRED ON DELETE CASCADE constraint, it doesn't really work
as I expected. I expected it to defer the deletion to the end of the
transaction, but it dosn't.
Is there a way to replace the contents of a table which has foreign keys?
There's no MERGE/UPSERT/whatever either.
=========
SELECT version();
version
-------------------------------------------------------------------------------------------------------------
PostgreSQL 8.4.4 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.4.real
(Ubuntu 4.4.3-4ubuntu5) 4.4.3, 64-bit
(1 row)
CREATE TABLE product (id INT PRIMARY KEY);
CREATE TABLE product_item (product_id INT REFERENCES product(id) ON DELETE
CASCADE DEFERRABLE INITIALLY DEFERRED);
INSERT INTO product VALUES (5);
INSERT INTO product_item VALUES (5);
BEGIN;
DELETE FROM product;
INSERT INTO product VALUES (5);
COMMIT;
SELECT * FROM product_item;
product_id
------------
(0 rows)
=============
From | Date | Subject | |
---|---|---|---|
Next Message | Sam Mason | 2010-09-01 16:12:43 | Re: Connection question |
Previous Message | Ivan Voras | 2010-09-01 15:36:49 | Re: Table update problem works on MySQL but not Postgres |