Re: referential integrity problem

From: Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com>
To: Joseph Artsimovich <joseph_a(at)mail(dot)ru>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: referential integrity problem
Date: 2002-02-18 01:10:11
Message-ID: 20020217170311.J66758-100000@megazone23.bigpanda.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 17 Feb 2002, Joseph Artsimovich wrote:

> Here is my problem:
>
> CREATE TABLE users (
> id SERIAL PRIMARY KEY
> );
>
> CREATE TABLE orders (
> id SERIAL PRIMARY KEY,
> user_id INT NOT NULL REFERENCES users ON DELETE CASCADE
> );
>
> CREATE TABLE orders_log (
> order_id INT NOT NULL REFERENCES orders ON DELETE CASCADE,
> by_user INT REFERENCES users ON DELETE SET NULL
> );
>
> Now suppose i do:
>
> INSERT INTO users DEFAULT VALUES;
> INSERT INTO orders (user_id) VALUES (currval('users_id_seq'));
> INSERT INTO orders_log (order_id, by_user) VALUES (currval('orders_id_seq'),
> currval('users_id_seq'));
> DELETE FROM users WHERE id=currval('users_id_seq');
>
> That last delete gives me a referential integrity violation error.
> I've figured out that if I mark the by_user reference as INITIALLY DEFERRED,
> then it works fine. But I don't understand why it refuses to work as is.
> I use PostgreSQL 7.1.3

I think this is possibly the known bug where intermediate states can
sometimes been seen by the referential integrity constraints. I believe
that part of a patch I'd sent to -patches a while back would probably
correct the situtation. I didn't try applying it to 7.1, but it probably
would apply. You can probably find it in the archives, or I can try to
find it and send it if you can't.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bart Teeuwisse 2002-02-18 01:58:40 parse error in timestamp function
Previous Message Andrew Snow 2002-02-17 23:02:07 Re: Database Performance?