Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uk6lO-0001r8-1i for pgsql-bugs@arkaria.postgresql.org; Wed, 05 Jun 2013 06:00:02 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Uk6lM-0002iP-UZ for pgsql-bugs@arkaria.postgresql.org; Wed, 05 Jun 2013 06:00:00 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Uk6lK-0002iH-TW for pgsql-bugs@postgresql.org; Wed, 05 Jun 2013 05:59:59 +0000 Received: from szxga01-in.huawei.com ([119.145.14.64]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Uk6lC-0005IW-Sh for pgsql-bugs@postgresql.org; Wed, 05 Jun 2013 05:59:58 +0000 Received: from 172.24.2.119 (EHLO szxeml205-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BDF60830; Wed, 05 Jun 2013 13:59:46 +0800 (CST) Received: from SZXEML454-HUB.china.huawei.com (10.82.67.197) by szxeml205-edg.china.huawei.com (172.24.2.58) with Microsoft SMTP Server (TLS) id 14.1.323.7; Wed, 5 Jun 2013 13:58:59 +0800 Received: from blrprnc09ns (10.18.96.98) by SZXEML454-HUB.china.huawei.com (10.82.67.197) with Microsoft SMTP Server id 14.1.323.7; Wed, 5 Jun 2013 13:58:58 +0800 From: Amit Kapila To: "=?UTF-8?Q?'Rafa=C5=82_Rzepecki'?=" , CC: "'Tom Lane'" References: <51adc2f4.65cc440a.3921.ffffdd76SMTPIN_ADDED_BROKEN@mx.google.com> In-Reply-To: Subject: Re: BUG #8198: ROW() literals not supported in an IN clause Date: Wed, 5 Jun 2013 11:28:56 +0530 Message-ID: <005101ce61b1$c5384cf0$4fa8e6d0$@kapila@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Office Outlook 12.0 Thread-Index: Ac5hgDyOT1nSGdYxTEKq+Ps9eCVXngAMO7sQ Content-Language: en-us X-Originating-IP: [10.18.96.98] X-CFilter-Loop: Reflected X-Pg-Spam-Score: 0.6 (/) 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 On Wednesday, June 05, 2013 5:34 AM Rafa=C5=82 Rzepecki wrote: > On Tue, Jun 4, 2013 at 12:35 PM, Amit Kapila > wrote: > > On Saturday, June 01, 2013 9:37 PM > > > >> Row type literals constructed with ROW() cause an error when used in > >> an IN clause (string literals casted appropriately are allowed). > This > >> is especially problematic since many client libraries use these > >> literals to pass values of row-type arguments, hence making it > >> impossible to use them in IN-clause queries. > >> >=20 > If I'm right, the proper fix would be (patch 0001; caution, not > tested): >=20 > --- a/src/backend/parser/parse_expr.c > +++ b/src/backend/parser/parse_expr.c > @@ -1203,10 +1203,9 @@ transformAExprIn(ParseState *pstate, A_Expr *a) > Node *rexpr =3D (Node *) lfirst(l); > Node *cmp; >=20 > - if (haveRowExpr) > + if (haveRowExpr && IsA(lexpr, RowExpr)) > { > - if (!IsA(lexpr, RowExpr) || > - !IsA(rexpr, RowExpr)) > + if (!IsA(rexpr, RowExpr)) > ereport(ERROR, >=20 > (errcode(ERRCODE_SYNTAX_ERROR), > errmsg("arguments of row IN must all > be row expressions"), >=20 >=20 > Since the restriction seems a rather arbitrary (at least I fail to see > any reason for it), it can be removed altogether (patch 0002, not > tested as well): >=20 > --- a/src/backend/parser/parse_expr.c > +++ b/src/backend/parser/parse_expr.c > @@ -1203,20 +1203,12 @@ transformAExprIn(ParseState *pstate, A_Expr *a) > Node *rexpr =3D (Node *) lfirst(l); > Node *cmp; >=20 > - if (haveRowExpr) > - { > - if (!IsA(lexpr, RowExpr) || > - !IsA(rexpr, RowExpr)) > - ereport(ERROR, > - > (errcode(ERRCODE_SYNTAX_ERROR), > - errmsg("arguments of row IN must > all be row expressions"), > - > parser_errposition(pstate, a->location))); > + if (IsA(lexpr, RowExpr) && IsA(rexpr, RowExpr)) > cmp =3D make_row_comparison_op(pstate, >=20 > a->name, > (List *) > copyObject(((RowExpr *) lexpr)->args), >=20 > ((RowExpr *) rexpr)->args, >=20 > a->location); > - } > else > cmp =3D (Node *) make_op(pstate, > a- > >name, >=20 I had tried, both your patches have passed all regression tests (tested on = Windows). I feel fixing it in a way similar to your Patch-1 would be more appropriate as with Patch-1 it can generate meaningful error message f= or some cases like below: postgres=3D# select * from the_table where ROW('abc','def') in (row('foo','= bar')::the_row,12);=20 ERROR: arguments of row IN must all be row expressions=20 LINE 1: select * from the_table where ROW('abc','def') in (row('foo'... With Regards, Amit Kapila. --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs