From: achill@matrix.gatewaynet.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14679: Inconsistent/wrong behavior of pg_trigger_depth when used with DEFERRED CONSTRAINTS
Date: Tue, 30 May 2017 06:55:58 +0000
Message-ID: <20170530065558.4284.28679@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 14679
Logged by: Achilleas Mantzios
Email address: achill@matrix.gatewaynet.com
PostgreSQL version: 9.5.6
Operating system: Ubuntu 16.04.1 LTS , 4.4.0-38-generic
Description:
I just run into a behavior that I consider wrong. Test case :
create table test(id serial primary key, name text);
CREATE OR REPLACE FUNCTION public.force_integrity()
RETURNS trigger
LANGUAGE plpgsql
AS $function$DECLARE
BEGIN
RAISE NOTICE 'TABLE = %.% , pg_trigger_depth()=%',TG_TABLE_SCHEMA,
TG_TABLE_NAME, pg_trigger_depth();
IF (pg_trigger_depth() = 1) THEN
UPDATE test SET id=id WHERE id=NEW.id;
END IF;
RETURN NEW;
END;
$function$
CREATE CONSTRAINT TRIGGER test_force_integrity_tg
AFTER INSERT OR UPDATE
ON test
DEFERRABLE INITIALLY DEFERRED
FOR EACH ROW
EXECUTE PROCEDURE force_integrity();
-- test by forcing immediate constraints and thus expected results
begin;
BEGIN
set CONSTRAINTS ALL IMMEDIATE;
insert into test(name) values ('foo');
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=2
CONTEXT: SQL statement "UPDATE test SET id=id WHERE id=NEW.id"
PL/pgSQL function force_integrity() line 9 at SQL statement
INSERT 0 1
commit;
COMMIT
-- test with defaults - unexpected results
begin ;
BEGIN
insert into test(name) values ('foo');
INSERT 0 1
commit ;
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
NOTICE: TABLE = public.test , pg_trigger_depth()=1
-- Endless loop, pg_trigger_depth() never gets increased
This was reproduced on 9.3.17 and on 9.5.6
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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: achill@matrix.gatewaynet.com
Subject: Re: BUG #14679: Inconsistent/wrong behavior of pg_trigger_depth when used with DEFERRED CONSTRAINTS
In-Reply-To: <20170530065558.4284.28679@wrigleys.postgresql.org>
References: <20170530065558.4284.28679@wrigleys.postgresql.org>
* 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