From: Amit Kapila <amit.kapila@huawei.com>
To: 'Борис Ромашов' <boraldomaster@gmail.com>
To: 'Tom Lane' <tgl@sss.pgh.pa.us>
Cc: 'pgsql-bugs' <pgsql-bugs@postgresql.org>
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> (raw)
In-Reply-To: <CAJh38TNwLmGZCveCBDyGpWvrKYomHzt_uuB44sh-Pbj7jGqPYw@mail.gmail.com>
References: <E1Upc8w-0003OT-U0@wrigleys.postgresql.org>
<24774.1371756513@sss.pgh.pa.us>
<CAJh38TN-gSC=RPb8efV_Tsd8mU4h4NUty=BMj+5nc=N9JS7ujg@mail.gmail.com>
<CAJh38TNwLmGZCveCBDyGpWvrKYomHzt_uuB44sh-Pbj7jGqPYw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
On Friday, June 21, 2013 1:24 PM Борис Ромашов 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 Борис Ромашов <boraldomaster@gmail.com>
> 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 in Oracle) - I could construct more complex external query such that subquery
> 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 = 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
> 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.
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 returns more than one row when it is not expected.
In some cases it is okay even if subquery expression returns more than one row, for example:
postgres=# select 1 In (select generate_series(1,2));
?column?
----------
t
(1 row)
postgres=# select 4 In (select generate_series(1,2));
?column?
----------
f
(1 row)
postgres=# select 1 = (select generate_series(1,2));
ERROR: more than one row returned by a subquery used as an expression
postgres=#
Why do you want to know the exact row due to which this happens, and what you want to do with it?
With Regards,
Amit Kapila.
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: amit.kapila@huawei.com, boraldomaster@gmail.com, tgl@sss.pgh.pa.us
Subject: Re: BUG #8242: No way to debug "subquery must return only one column" error
In-Reply-To: <010201ce70ab$e4bb1ef0$ae315cd0$@kapila@huawei.com>
References: <E1Upc8w-0003OT-U0@wrigleys.postgresql.org> <24774.1371756513@sss.pgh.pa.us> <CAJh38TN-gSC=RPb8efV_Tsd8mU4h4NUty=BMj+5nc=N9JS7ujg@mail.gmail.com> <CAJh38TNwLmGZCveCBDyGpWvrKYomHzt_uuB44sh-Pbj7jGqPYw@mail.gmail.com> <010201ce70ab$e4bb1ef0$ae315cd0$@kapila@huawei.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox