From: André Hänsel <andre@webkr.de>
To: pgsql-bugs@lists.postgresql.org
Subject: Deferred foreign key and two updates block ALTER TABLE
Date: Mon, 21 Jan 2019 02:31:04 +0100
Message-ID: <04ab01d4b128$fa63f510$ef2bdf30$@webkr.de> (raw)
Hi list,
this looks like a bug to me, forgive me if it's expected behavior:
BEGIN;
DROP TABLE IF EXISTS test;
DROP TABLE IF EXISTS test_other;
CREATE TABLE test(
some_column integer NOT NULL,
other_id integer NOT NULL
);
CREATE TABLE test_other(
other_id integer NOT NULL
);
ALTER TABLE test_other ADD PRIMARY KEY (other_id);
ALTER TABLE test ADD FOREIGN KEY (other_id) REFERENCES test_other
DEFERRABLE;
INSERT INTO test_other (other_id) VALUES (1);
INSERT INTO test (some_column, other_id) VALUES (0, 1);
COMMIT;
BEGIN;
SET CONSTRAINTS ALL DEFERRED;
UPDATE test SET some_column = 1 WHERE some_column = 0;
UPDATE test SET some_column = 2 WHERE some_column = 1;
ALTER TABLE test ALTER COLUMN some_column TYPE smallint;
COMMIT;
Expected result: Both transactions can be committed without error
Actual result: ERROR: cannot ALTER TABLE "test" because it has pending
trigger events SQL state: 55006
Notes:
- It doesn't matter if the UPDATEs are on the same or different colums that
are altered, there is still an error
- There is no error if there is just one UPDATE instead of two (this makes
me think this might be a bug)
- There is no error if both UPDATEs lead to the same result (when the second
UPDATE is a no-op, like setting some_column = 1 again)
- There is no error if the foreign key is non-deferrable or currently
immediate
Regards,
André
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: andre@webkr.de
Subject: Re: Deferred foreign key and two updates block ALTER TABLE
In-Reply-To: <04ab01d4b128$fa63f510$ef2bdf30$@webkr.de>
References: <04ab01d4b128$fa63f510$ef2bdf30$@webkr.de>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox