INITIALLY DEFERRED / UPDATE in transaction bug

From: "Robert B(dot) Easter" <reaster(at)comptechnews(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: INITIALLY DEFERRED / UPDATE in transaction bug
Date: 2000-07-09 13:01:54
Message-ID: 0007090906400E.01354@comptechnews
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

============================================================================
POSTGRESQL BUG REPORT TEMPLATE
============================================================================

Your name : Robert B. Easter
Your email address : reaster(at)comptechnews(dot)com

System Configuration
---------------------
Architecture (example: Intel Pentium) : Intel Celeron

Operating System (example: Linux 2.0.26 ELF) : Linux 2.2.13 Slackware

PostgreSQL version (example: PostgreSQL-7.0): PostgreSQL-7.0.2

Compiler used (example: gcc 2.8.0) : egcs-2.91.66

Please enter a FULL description of your problem:
------------------------------------------------
Referential integrity problem.

When using an INITIALLY DEFERRED foreign key within a transaction,
I give it a value that is not in the referenced table. Then I UPDATE
it so that it has a value in the referenced table. Then I COMMIT.
I still get an RI error on COMMIT.

Please describe a way to repeat the problem. Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------

CREATE TABLE t1 (
t2_id INTEGER NOT NULL
);

CREATE TABLE t2 (
id SERIAL PRIMARY KEY
);

ALTER TABLE t1 ADD CONSTRAINT t1_t2_id_fk FOREIGN KEY (t2_id) REFERENCES t2 INITIALLY DEFERRED;

BEGIN;
INSERT INTO t1 VALUES (0);
INSERT INTO t2 VALUES (1);
SELECT t2_id FROM t1;
SELECT id FROM t2;
UPDATE t1 SET t2_id = 1 WHERE t2_id = 0;
SELECT t2_id FROM t1;
SELECT id FROM t2;
COMMIT; -- error

-- Or

CREATE TABLE t3 (
id SERIAL PRIMARY KEY
);

CREATE TABLE t4 (
t3_id INTEGER REFERENCES t3 INITIALLY DEFERRED
);

BEGIN;
INSERT INTO t4 VALUES (0);
INSERT INTO t3 VALUES (1);
SELECT t3_id FROM t4;
SELECT id FROM t3;
UPDATE t4 SET t3_id = 1 WHERE t3_id = 0;
SELECT t3_id FROM t4;
SELECT id FROM t3;
COMMIT; -- again, error

If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------

--
Robert

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2000-07-09 17:38:52 Re: Unnexpected results using to_number()
Previous Message Andrew McMillan 2000-07-09 10:42:39 Periodic freezing of backend processes