Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1b8xby-000793-Up for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jun 2016 22:30:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1b8xby-0005O1-3N for pgsql-hackers@arkaria.postgresql.org; Fri, 03 Jun 2016 22:30:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1b8x91-00027p-4t for pgsql-hackers@postgresql.org; Fri, 03 Jun 2016 22:00:43 +0000 Received: from mail-lf0-x233.google.com ([2a00:1450:4010:c07::233]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1b8x8y-0007DE-1g for pgsql-hackers@postgresql.org; Fri, 03 Jun 2016 22:00:41 +0000 Received: by mail-lf0-x233.google.com with SMTP id w16so62620235lfd.2 for ; Fri, 03 Jun 2016 15:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=e-djuster-com.20150623.gappssmtp.com; s=20150623; h=from:mime-version:thread-index:date:message-id:subject:to; bh=gb+OF0IeWFC84yGQNb7zx1Y+uRGcmapSJfv39Wf+Yss=; b=Pv2F2Dn2iqavLKEaMg+YxbHo446HbXtwYeGlhsR6QMUIBXMc0EUUnbsLdZbDH6+uj7 dg6MCGHjAni3DyJl9hRs1ijdQODUa4vlxRI5LgDrYVRhS6cqVfkfsyUFX7I4sDYucX79 UnmkZSMD195DoK13GANQ/wc//AtSvTSKm0f88oND4o/P6SLQUqD91UfHkINyLy33HU9V YKh2wLxlk5+TqBMIUwoDXtMxwODjEsodiArNy6ppwVvE2Vn3FdfxOK7ZasgSfnyAqYH6 XkpYgNBZUGttB11sBJld5uU+PJyDP7LRXs5YvCvIRh1dOq0tOin1ggGVf386Uj+0Oom7 j58w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:mime-version:thread-index:date:message-id :subject:to; bh=gb+OF0IeWFC84yGQNb7zx1Y+uRGcmapSJfv39Wf+Yss=; b=Dtr3SYygHAVMTqrbz3hSbqm7buIJvPzSXZRgdTw0nTgf5mzO1UG7G+TkVDYsgzqxsT FcBb622YU6ySVGIdYnmU9jAFLziGgQDaDAxDPY948mjH/nKx80dsKemmkRhZIyg7mdhX 6S39VNV4EycXF+fHF8hdasTcwj6S+bXQ3jrPzQ+ylGXWkaif7BxFCCvTmkIYXQTcn/bL Oj1KEx0uoE5GO/iRF30Xu+Wh7IgOGIg/2YjBrLUwQc6wuzce5pbQUZoHFwFgIw2y04Tz A2lzTAorQBlpASSK60vQjW2r+v4I7LnXKeJZYM2SlNuke0P2zyQxV+D1VY4U4l8qegql i6sw== X-Gm-Message-State: ALyK8tKDqJn6P9JxfPMblYh++zUOmzKhJae7iZ8tWpjedvHQf495qf7UVz0urYq1mcSmtm99N50wZHoeU2lIVlc0 X-Received: by 10.46.5.82 with SMTP id 79mr1608698ljf.64.1464991237399; Fri, 03 Jun 2016 15:00:37 -0700 (PDT) From: Jean-Pierre Pelletier MIME-Version: 1.0 X-Mailer: Microsoft Outlook 14.0 Thread-Index: AdG94j8787l4J/x+RTitY427IizFNw== Date: Fri, 3 Jun 2016 18:00:36 -0400 Message-ID: Subject: Number of parentheses in check constraints affected by operator_precedence_warning To: pgsql-hackers@postgresql.org Content-Type: text/plain; charset=UTF-8 X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org 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