pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Markus Schaber <schabi@logix-tt.com>
Cc: PostgreSQL SQL List <pgsql-sql@postgresql.org>
Subject: Re: Set generating functions and subqueries
Date: Fri, 10 Mar 2006 09:48:48 -0500
Message-ID: <5142.1142002128@sss.pgh.pa.us> (raw)
In-Reply-To: <44116ED2.9060901@logix-tt.com>
References: <44116ED2.9060901@logix-tt.com>

Markus Schaber <schabi@logix-tt.com> writes:
> postgres=# select (select generate_series(1,2)),'othercol';
> ERROR:  more than one row returned by a subquery used as an expression

> So it seems that set-returning functions "blow up" the resultset by
> duplicating rows - so why is this not allowed for subqueries?

The behavior of the subquery expression is dictated by the SQL spec:

         1) If the cardinality of a <scalar subquery> or a <row subquery> is
            greater than 1, then an exception condition is raised: cardinal-
            ity violation.

The fact that the other form is even allowed is more of a holdover from
PostQUEL than something we have consciously decided is a good idea.
(IMHO it's actually a fairly *bad* idea, because it does not work nicely
when there's more than one SRF in the same targetlist.)  It'll probably
get phased out someday, if we can find a way to replace the
functionality.  I seem to recall speculating that SQL2003's LATERAL
tables might do the job.

> Btw, having several set-returning functions with equal or different set
> lengths produce interesting results:

No kidding.

			regards, tom lane



view thread (4+ messages)  latest in thread

Message-ID: <5142.1142002128@sss.pgh.pa.us>
Permalink:  ../5142.1142002128@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5142.1142002128@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, schabi@logix-tt.com
  Subject: Re: Set generating functions and subqueries
  In-Reply-To: <5142.1142002128@sss.pgh.pa.us>

* 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