From finkel@sd-il.com Mon Oct 20 05:59:03 2014 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xg5zj-0004qQ-SF for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Oct 2014 05:59:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xg5zj-0001nr-9D for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Oct 2014 05:59:03 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XfDQd-00081U-NH for pgsql-bugs@postgresql.org; Fri, 17 Oct 2014 19:43:11 +0000 Received: from wrigleys.postgresql.org ([204.145.124.246]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XfDQX-00014a-Pv for pgsql-bugs@postgresql.org; Fri, 17 Oct 2014 19:43:08 +0000 MIME-Version: 1.0 Subject: BUG #11705: \d(escribe) table shows incorrect check constraint To: pgsql-bugs@postgresql.org From: finkel@sd-il.com Date: Fri, 17 Oct 2014 19:42:58 +0000 Message-ID: <20141017194258.2957.58603@wrigleys.postgresql.org> X-Pg-Spam-Score: -1.9 (-) Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 11705 Logged by: Joel Finkel Email address: finkel@sd-il.com PostgreSQL version: 9.1.13 Operating system: x86_64-unknown-linux-gnu Description: We have a table with this constraint: CONSTRAINT check_m_nullability CHECK (((m1 IS NULL) AND (m2 IS NULL)) OR ((m1 IS NOT NULL) AND (m2 IS NOT NULL))) When we \d it is listed as: Check constraints: "check_m_nullability" CHECK (m1 IS NULL AND m2 IS NULL OR m1 IS NOT NULL AND m2 IS NOT NULL)" The application of the constraint appears to be correct. The problem is that \d is dropping important parentheses in its output; so it is showing an incorrect description. -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs From michael.paquier@gmail.com Mon Oct 20 06:45:28 2014 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Xg6ie-0006ej-3N for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Oct 2014 06:45:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Xg6id-0000oU-JX for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Oct 2014 06:45:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1Xg6ic-0000o5-UX for pgsql-bugs@postgresql.org; Mon, 20 Oct 2014 06:45:26 +0000 Received: from mail-qg0-x231.google.com ([2607:f8b0:400d:c04::231]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1Xg6iY-0007kS-SD for pgsql-bugs@postgresql.org; Mon, 20 Oct 2014 06:45:25 +0000 Received: by mail-qg0-f49.google.com with SMTP id e89so2965751qgf.8 for ; Sun, 19 Oct 2014 23:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=uG71bXn6SbXdOuRh02K4gDBHAFnTrVzv70CKydsuEew=; b=YufRJ9RBLs81iuJS8jGISW7AR4ZONLMIBrPa0Ia7vcqEiufNQuYRRq41o1BPT8OGqv NKJ78U7kIh29CgK52xp/i34YlxWXw+FXrpdqjF5XvZy2vM1cKdjVMS5QYSXM1x+vofL5 TTLaQWNmVQ2REBMS/7hvFxzAF9FKHzVa9P1zSSf6k0nD6kYihFFqey3Vb8tpWumuWYEZ tcEh0gBIbABi9Mgwu86WDQCK5bPG/KkIQCUoS4WDPqmp41vfOF+T9yBnAgUYyUXB8dAr SlVrJ6bLK8cvfvTFEgq+FUu67lDdyWcaTdv9/++YerYe1U407PuQk8KiGi7P9taVYAko RM5w== MIME-Version: 1.0 X-Received: by 10.224.1.200 with SMTP id 8mr31903798qag.54.1413787520115; Sun, 19 Oct 2014 23:45:20 -0700 (PDT) Received: by 10.140.104.145 with HTTP; Sun, 19 Oct 2014 23:45:20 -0700 (PDT) In-Reply-To: <20141017194258.2957.58603@wrigleys.postgresql.org> References: <20141017194258.2957.58603@wrigleys.postgresql.org> Date: Mon, 20 Oct 2014 15:45:20 +0900 Message-ID: Subject: Re: BUG #11705: \d(escribe) table shows incorrect check constraint From: Michael Paquier To: finkel@sd-il.com Cc: pgsql-bugs@postgresql.org Content-Type: multipart/alternative; boundary=001a11c2cefeeca80f0505d50eb3 X-Pg-Spam-Score: -2.7 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --001a11c2cefeeca80f0505d50eb3 Content-Type: text/plain; charset=ISO-8859-1 On Sat, Oct 18, 2014 at 4:42 AM, wrote: > We have a table with this constraint: > > CONSTRAINT check_m_nullability CHECK (((m1 IS NULL) AND (m2 IS NULL)) OR > ((m1 IS NOT NULL) AND (m2 IS NOT NULL))) > > When we \d
it is listed as: > > Check constraints: > "check_m_nullability" CHECK (m1 IS NULL AND m2 IS NULL OR m1 IS NOT NULL > AND m2 IS NOT NULL)" > > The application of the constraint appears to be correct. The problem is > that \d is dropping important parentheses in its output; so it is showing an > incorrect description. The description is correct AFAIK, this can survive without parenthesis as AND clauses take precedence on OR. Note that psql uses pg_constraint_def to generate this description, with pretty_bool set to true (2nd parameter of this function set to false by default) to make the output more lisible, so you could always reuse it for a custom query like that: =# create table aa (a int, b int, check (a is null and b is null or a is not null and b is not null)); CREATE TABLE =# select pg_get_constraintdef(oid) from pg_constraint where conrelid = 'ab'::regclass; pg_get_constraintdef ---------------------------------------------------------------------------------- CHECK ((((a IS NULL) AND (b IS NULL)) OR ((a IS NOT NULL) AND (b IS NOT NULL)))) (1 row) =# select pg_get_constraintdef(oid, true) from pg_constraint where conrelid = 'ab'::regclass; pg_get_constraintdef -------------------------------------------------------------------- CHECK (a IS NULL AND b IS NULL OR a IS NOT NULL AND b IS NOT NULL) (1 row) -- Michael --001a11c2cefeeca80f0505d50eb3 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable


On Sat, Oct 18, 2014 at 4:42 AM, =A0<finkel@sd-il.com> wrote:
> We h= ave a table with this constraint:
>
> CONSTRAINT check_m_nullab= ility CHECK (((m1 IS NULL) AND (m2 IS NULL)) OR
> ((m1 IS NOT NULL) A= ND (m2 IS NOT NULL)))
>
> When we \d <table name> it is l= isted as:
>
> Check constraints:
> =A0 =A0 "check_m_= nullability" CHECK (m1 IS NULL AND m2 IS NULL OR m1 IS NOT NULL
>= ; AND m2 IS NOT NULL)"
>
> The application of the constrai= nt appears to be correct.=A0 The problem is
> that \d is dropping imp= ortant parentheses in its output; so it is showing an
> incorrect des= cription.
The description is correct AFAIK, this can survive witho= ut parenthesis as AND clauses take precedence on OR.

Note that = psql uses pg_constraint_def to generate this description, with pretty_bool = set to true (2nd parameter of this function set to false by default) to mak= e the output more lisible, so you could always reuse it for a custom query = like that:
=3D# create table aa (a int, b int, check (a is null and b is= null or a is not null and b is not null));
CREATE TABLE
=3D# select = pg_get_constraintdef(oid) from pg_constraint where conrelid =3D 'ab'= ;::regclass;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 pg_get_constraintdef
-----------------------------------------------= -----------------------------------
=A0CHECK ((((a IS NULL) AND (b IS NU= LL)) OR ((a IS NOT NULL) AND (b IS NOT NULL))))
(1 row)
=3D# select p= g_get_constraintdef(oid, true) from pg_constraint where conrelid =3D 'a= b'::regclass;
=A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 pg_get= _constraintdef
---------------------------------------------------------= -----------
=A0CHECK (a IS NULL AND b IS NULL OR a IS NOT NULL AND b IS = NOT NULL)
(1 row)
-- =
Michael
--001a11c2cefeeca80f0505d50eb3-- From kgrittn@ymail.com Mon Oct 20 20:44:51 2014 Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XgJox-0003GS-GU for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Oct 2014 20:44:51 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XgJow-0002C4-PD for pgsql-bugs@arkaria.postgresql.org; Mon, 20 Oct 2014 20:44:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XgJov-0002By-Qa for pgsql-bugs@postgresql.org; Mon, 20 Oct 2014 20:44:50 +0000 Received: from nm20-vm4.bullet.mail.ne1.yahoo.com ([98.138.91.180]) by makus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XgJos-0007G3-1u for pgsql-bugs@postgresql.org; Mon, 20 Oct 2014 20:44:48 +0000 Received: from [98.138.100.118] by nm20.bullet.mail.ne1.yahoo.com with NNFMP; 20 Oct 2014 20:44:44 -0000 Received: from [98.138.89.169] by tm109.bullet.mail.ne1.yahoo.com with NNFMP; 20 Oct 2014 20:44:23 -0000 Received: from [127.0.0.1] by omp1025.mail.ne1.yahoo.com with NNFMP; 20 Oct 2014 20:44:23 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 10265.96219.bm@omp1025.mail.ne1.yahoo.com Received: (qmail 1299 invoked by uid 60001); 20 Oct 2014 20:44:22 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1413837862; bh=8pdk3QkWdg4uLQhi/QfrXjqzuF5eDScE3u3BmAoXAmo=; h=References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=NCAuHewiPBlqgtR0YEYsmxcz9/dG/EplsVjde6M0qgsy+XC1kN8FtT7eY+XfVrFKbNw3z99WupHDr1231+fmS+7G5L4B4AbtHruQq0KDYftk+Jm0LwXLF0IwzBL3EQc/C02tIpWrtltFipyH9SndFtpgcYRZpajnFmBbF+1gOCo= X-YMail-OSG: SKxC1CgVM1kTTtp5hEqi3U1ap2WBNeZoWYYV2Q_C6pdsJK7 6LLk4Sp..DnZwhI60EogxkZiEzqQRD29ok4dISpHlbp2GEnD8rFkO9j.fEiM _iiG7WXv9V6zydqLL_w_gjpgET5zfDl6_9C2oBS2RkjuOVbCQ3FqF2eT6ny6 xw2bDK16e0MyOWObKQGZL6z5un793ZZWA0QSxYIh7pFGlyWtsY1qgfypwupQ Rqgq.ZkaL26b4CwfTA4DdW8o_dLRmRuQ7AjKo6xSVbE0g6NO.7sbI3ptbxKa j8zuvo_5WgDP6G_cCqYk19_26FR0yONsvgpkgbWaEfleLkAYRWpriSmmEcD5 _hDf.QVmJFgzTDQ9T1W3b9rQfZ77R6pXxQJmWl_avQIylo7nf05SnummVczj 0PvPBENr7RepmsWfXn_v55IRaqBYnNdj9AtxSkRwx3IpPRcPkbfZjId8l3fm .0DQUe19Sbjl5en7WPZNNuu7.n9EM0p5mjKaPwF4_w7DMZb5eC7_Kd.J0v45 .35XgDUHR7exVhjpioYZi3IJULj9G3XI5JHwtP_stDqMpTVegK8qrN_8_gKs hLbTWILjp3gxNTDyGpZqj Received: from [71.87.18.210] by web122301.mail.ne1.yahoo.com via HTTP; Mon, 20 Oct 2014 13:44:22 PDT X-Rocket-MIMEInfo: 002.001, ImZpbmtlbEBzZC1pbC5jb20iIDxmaW5rZWxAc2QtaWwuY29tPiB3cm90ZToKPiBXZSBoYXZlIGEgdGFibGUgd2l0aCB0aGlzIGNvbnN0cmFpbnQ6Cgo.Cj4gQ09OU1RSQUlOVCBjaGVja19tX251bGxhYmlsaXR5IENIRUNLICgoKG0xIElTIE5VTEwpIEFORAo.IChtMiBJUyBOVUxMKSkgT1IgKChtMSBJUyBOT1QgTlVMTCkgQU5EIChtMiBJUyBOT1QgTlVMTCkpKQoKTWljaGFlbCBpcyByaWdodCwgYnV0IGluIGFkZGl0aW9uIHRvIHRoYXQgeW91IG1pZ2h0IHdhbnQgdG8gdXNlIHRoZQpzaW1wbGVyIChhbmQgdG8BMAEBAQE- X-Mailer: YahooMailWebService/0.8.203.733 References: <20141017194258.2957.58603@wrigleys.postgresql.org> Message-ID: <1413837862.43723.YahooMailNeo@web122301.mail.ne1.yahoo.com> Date: Mon, 20 Oct 2014 13:44:22 -0700 From: Kevin Grittner Reply-To: Kevin Grittner Subject: Re: BUG #11705: \d(escribe) table shows incorrect check constraint To: "finkel@sd-il.com" , "pgsql-bugs@postgresql.org" In-Reply-To: <20141017194258.2957.58603@wrigleys.postgresql.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Pg-Spam-Score: -0.5 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org "finkel@sd-il.com" wrote: > We have a table with this constraint: > > CONSTRAINT check_m_nullability CHECK (((m1 IS NULL) AND > (m2 IS NULL)) OR ((m1 IS NOT NULL) AND (m2 IS NOT NULL))) Michael is right, but in addition to that you might want to use the simpler (and to my eye easier to read): CONSTRAINT check_m_nullability CHECK ((m1 IS NULL) = (m2 IS NULL)) -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs