pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Number of parentheses in check constraints affected by operator_precedence_warning
2+ messages / 2 participants
[nested] [flat]

* Number of parentheses in check constraints affected by operator_precedence_warning
@ 2016-06-03 22:00 Jean-Pierre Pelletier <jppelletier@e-djuster.com>
  2016-06-03 23:13 ` Re: Number of parentheses in check constraints affected by operator_precedence_warning Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Jean-Pierre Pelletier @ 2016-06-03 22:00 UTC (permalink / raw)
  To: pgsql-hackers

Hi,

We noticed on PostgreSQL 9.5.3 that the number of parentheses in check
constraints expressions
vary depending on the setting of operator_precedence_warning.

-- The following reproduces this issue which we first saw by restoring
into 9.5.3 a 9.4.8 dump
on two servers which had different operator_precedence_warning.

SET operator_precedence_warning = off; -- on would yield a different
number of parentheses

DROP TABLE IF EXISTS t1;
CREATE TABLE t1 (col1 INT, col2 INT, col3 INT, col4 INT);

-- 1) Check Constraints

ALTER TABLE t1
   ADD CONSTRAINT cc1 CHECK ((col1 IS NULL) OR (((col2 IS NULL) AND (col3
IS NULL)) AND (col4 IS NULL))),
   ADD CONSTRAINT cc2 CHECK (((col1 IS NOT NULL) OR (col2 IS NOT NULL)) OR
(col3 IS NOT NULL));


SELECT conname, consrc FROM pg_constraint WHERE conrelid = 't1'::regclass;

-- With  9.5.3 operator_precedence_warning = on (or pg 9.4)
-- cc1 ((col1 IS NULL) OR (((col2 IS NULL) AND (col3 IS NULL)) AND (col4
IS NULL)))
-- cc2 (((col1 IS NOT NULL) OR (col2 IS NOT NULL)) OR (col3 IS NOT NULL))

-- With 9.5.3 operator_precedence_warning = off
-- cc1 ((col1 IS NULL) OR ((col2 IS NULL) AND (col3 IS NULL) AND (col4 IS
NULL)))
-- cc2 ((col1 IS NOT NULL) OR (col2 IS NOT NULL) OR (col3 IS NOT NULL))


-- 2) WHEN condition on triggers also have this issue, for example:

DROP FUNCTION IF EXISTS f1();

CREATE FUNCTION f1() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
BEGIN
END;
$$;

CREATE TRIGGER tr1 BEFORE UPDATE ON t1 FOR EACH ROW WHEN (((((new.col1 IS
DISTINCT FROM old.col1) OR (new.col2 IS DISTINCT FROM old.col2)) OR
((new.col3 IS NOT NULL) AND (new.col3 IS DISTINCT FROM old.col3))) OR
((new.col3 IS NULL) AND (new.col3 IS DISTINCT FROM old.col3)))) EXECUTE
PROCEDURE f1();

We got these results on Windows x64.

Thanks,
Jean-Pierre Pelletier


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Number of parentheses in check constraints affected by operator_precedence_warning
  2016-06-03 22:00 Number of parentheses in check constraints affected by operator_precedence_warning Jean-Pierre Pelletier <jppelletier@e-djuster.com>
@ 2016-06-03 23:13 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2016-06-03 23:13 UTC (permalink / raw)
  To: Jean-Pierre Pelletier <jppelletier@e-djuster.com>; +Cc: pgsql-hackers

Jean-Pierre Pelletier <jppelletier@e-djuster.com> writes:
> We noticed on PostgreSQL 9.5.3 that the number of parentheses in check
> constraints expressions
> vary depending on the setting of operator_precedence_warning.

Hmm, yeah, another place that needs to look through AEXPR_PAREN nodes :-(.
Fixed, thanks for the report!

			regards, tom lane


-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2016-06-03 23:13 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-06-03 22:00 Number of parentheses in check constraints affected by operator_precedence_warning Jean-Pierre Pelletier <jppelletier@e-djuster.com>
2016-06-03 23:13 ` Tom Lane <tgl@sss.pgh.pa.us>

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