Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Ujoae-000139-O1 for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Jun 2013 10:35:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Ujoad-0005Lk-Ix for pgsql-bugs@arkaria.postgresql.org; Tue, 04 Jun 2013 10:35:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Ujoac-0005Le-KV for pgsql-bugs@postgresql.org; Tue, 04 Jun 2013 10:35:42 +0000 Received: from szxga01-in.huawei.com ([119.145.14.64]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UjoaW-00071W-Jc for pgsql-bugs@postgresql.org; Tue, 04 Jun 2013 10:35:42 +0000 Received: from 172.24.2.119 (EHLO szxeml210-edg.china.huawei.com) ([172.24.2.119]) by szxrg01-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BDE60972; Tue, 04 Jun 2013 18:35:27 +0800 (CST) Received: from SZXEML451-HUB.china.huawei.com (10.82.67.194) by szxeml210-edg.china.huawei.com (172.24.2.183) with Microsoft SMTP Server (TLS) id 14.1.323.7; Tue, 4 Jun 2013 18:35:11 +0800 Received: from blrprnc09ns (10.18.96.98) by szxeml451-hub.china.huawei.com (10.82.67.194) with Microsoft SMTP Server id 14.1.323.7; Tue, 4 Jun 2013 18:35:07 +0800 From: Amit Kapila To: , References: In-Reply-To: Subject: Re: BUG #8198: ROW() literals not supported in an IN clause Date: Tue, 4 Jun 2013 16:05:05 +0530 Message-ID: <000301ce610f$2ee8de60$8cba9b20$@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: Ac5glPo85mbIgHBnQd+w0/LKW1aLyQAeCd8g Content-Language: en-us X-Originating-IP: [10.18.96.98] X-CFilter-Loop: Reflected X-Pg-Spam-Score: -2.1 (--) 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 Saturday, June 01, 2013 9:37 PM=20 =20 > 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 > To wit: > divide=3D# create type the_row as (mfg text, id text); > CREATE TYPE > divide=3D# create table the_table (widget the_row); >=20 >=20 > CREATE TABLE >=20 >=20 > divide=3D# insert into the_table values(row('foo', 'bar')::the_row); >=20 >=20 > INSERT 0 1 >=20 >=20 > divide=3D# insert into the_table values('(bar,baz)'::the_row); >=20 >=20 > INSERT 0 1 > divide=3D# select * from the_table; > widget > ----------- > (foo,bar) > (bar,baz) > (2 rows) >=20 > divide=3D# select * from the_table where widget in > ('(foo,bar)'::the_row); > widget > ----------- > (foo,bar) > (1 row) >=20 > divide=3D# select * from the_table where widget in > (row('foo','bar')::the_row); > ERROR: arguments of row IN must all be row expressions > LINE 1: select * from the_table where widget in (row('foo','bar')::t... The similar query for equal ('=3D') operator works fine. select * from the_table where widget =3D (row('foo','bar')::the_row); The reason for above is that in function transformAExprOp(..), it uses make= _row_comparison_op() to operate on expressions only if both left and right = are row expressions, else it will use make_op() to operate on expressions. = Refer code below in function transformAExprOp()=20=20 else if (lexpr && IsA(lexpr, RowExpr) &&=20 rexpr && IsA(rexpr, RowExpr))=20 {=20 .... result =3D make_row_comparison_op(pstate,=20 = a->name,=20 = ((RowExpr *) lexpr)->args,=20 = ((RowExpr *) rexpr)->args,=20 = a->location);=20 }=20 else=20 {=20 .... result =3D (Node *) make_op(pstate,=20 a->name,= =20 lexpr,=20 rexpr,=20 a->locati= on);=20 } However for IN clause, if any one expr (left or right) is RowExpr, then it = will try to use make_row_comparison_op, which result in error. Refer below code of function transformAExprIn(): if (haveRowExpr)=20 {=20 if (!IsA(lexpr, RowExpr) ||=20 !IsA(rexpr, RowExpr))=20 ereport(ERROR,=20 (errcode(ERRCODE_SYNTAX_ERR= OR),=20 errmsg("arguments of row IN must all be = row expressions"),=20 parser_errposition(pstate,= a->location)));=20 cmp =3D make_row_comparison_op(pstate,=20 = a->name,=20 (List *) copyObje= ct(((RowExpr *) lexpr)->args),=20 = ((RowExpr *) rexpr)->args,=20 = a->location);=20 }=20 else=20 cmp =3D (Node *) make_op(pstate,=20 a->name,= =20 copyObje= ct(lexpr),=20 rexpr,= =20 a->locat= ion); Changing the functionality of transformAExprIn() similar to transformAExprO= p() will fix this issue, but not sure if there is any other side effect of = same. 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