Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ur18z-00084p-3r for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Jun 2013 07:24:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Ur18x-0005Hv-Mv for pgsql-bugs@arkaria.postgresql.org; Mon, 24 Jun 2013 07:24:55 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ur18w-0005Ho-Om for pgsql-bugs@postgresql.org; Mon, 24 Jun 2013 07:24:54 +0000 Received: from szxga02-in.huawei.com ([119.145.14.65]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Ur18s-00014P-Tt for pgsql-bugs@postgresql.org; Mon, 24 Jun 2013 07:24:54 +0000 Received: from 172.24.2.119 (EHLO szxeml205-edg.china.huawei.com) ([172.24.2.119]) by szxrg02-dlp.huawei.com (MOS 4.3.4-GA FastPath queued) with ESMTP id BDS98042; Mon, 24 Jun 2013 15:24:45 +0800 (CST) Received: from SZXEML405-HUB.china.huawei.com (10.82.67.60) by szxeml205-edg.china.huawei.com (172.24.2.58) with Microsoft SMTP Server (TLS) id 14.1.323.7; Mon, 24 Jun 2013 15:24:45 +0800 Received: from blrprnc09ns (10.18.96.98) by szxeml405-hub.china.huawei.com (10.82.67.60) with Microsoft SMTP Server id 14.1.323.7; Mon, 24 Jun 2013 15:24:41 +0800 From: Amit Kapila To: =?UTF-8?B?J9CR0L7RgNC40YEg0KDQvtC80LDRiNC+0LIn?= , "'Tom Lane'" CC: "'pgsql-bugs'" References: <24774.1371756513@sss.pgh.pa.us> In-Reply-To: Subject: Re: BUG #8242: No way to debug "subquery must return only one column" error Date: Mon, 24 Jun 2013 12:54:40 +0530 Message-ID: <010201ce70ab$e4bb1ef0$ae315cd0$@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: Ac5ulNnhysrN0cNxSb2OVhzmqxSjQwCE58uw Content-Language: en-us X-Originating-IP: [10.18.96.98] X-CFilter-Loop: Reflected 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 On Friday, June 21, 2013 1:24 PM =D0=91=D0=BE=D1=80=D0=B8=D1=81 =D0=A0=D0= =BE=D0=BC=D0=B0=D1=88=D0=BE=D0=B2 wrote: > I just realized that I wanted to ask about another error. > more than one row returned by a subquery used as an expression > not about > subquery must return only one column > 2013/6/21 =D0=91=D0=BE=D1=80=D0=B8=D1=81 =D0=A0=D0=BE=D0=BC=D0=B0=D1=88= =D0=BE=D0=B2 > Tom, suppose you haven't understood what the problem I'm facing with. > Let me explain deeper. > Try to execute the following 2 queries. > select (select generate_series(1,2)); > select (select generate_series(1,1)); > They differ only in data, both of them are well-written, so there is not = the problem in parsing. > But first query gives (even in psql) > ERROR: more than one row returned by a subquery used as an expression > Certainly - instead of generate_series I could write any usual query that= fetches some data from database. > And if this query returns one row - everything is correct. > And certainly, instead of selecting from dual (that is how it is called i= n Oracle) - I could construct more complex external query such that subquer= y=20 > could return "more than one row" for just in some exact row (not in each = row) of external record set. > Example > select id, (select friend.id from user friend where friend.id =3D user.id= ) user from user > This query fetches all users with their friends assuming that every user = has only one friend. > But if some of them will have 2 friends - this query will fail with=20 > ERROR: more than one row returned by a subquery used as an expression > And I will have no chance to guess - which user exactly this happened for= .=20 I don't think there is any way, you can know exactly for which this error= occurred. The main reason is that this error occurs when an expression subquery ret= urns more than one row when it is not expected. In some cases it is okay even if subquery expression returns more than on= e row, for example: postgres=3D# select 1 In (select generate_series(1,2));=20 ?column?=20 ----------=20 t=20 (1 row)=20 postgres=3D# select 4 In (select generate_series(1,2));=20 ?column?=20 ----------=20 f=20 (1 row)=20 postgres=3D# select 1 =3D (select generate_series(1,2));=20 ERROR: more than one row returned by a subquery used as an expression=20 postgres=3D# Why do you want to know the exact row due to which this happens, and what y= ou want to do with it? =20=20 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