PL/pgSQL PERFORM with CTE

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Josh Berkus <josh(at)agliodbs(dot)com>, Marko Tiikkaja <marko(at)joh(dot)to>, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Jan Wieck <JanWieck(at)yahoo(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, "David E(dot) Wheeler" <david(at)justatheory(dot)com>, pgsql-hackers Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: PL/pgSQL PERFORM with CTE
Date: 2013-08-24 12:40:42
Message-ID: CAHyXU0zciNup228RsTYzfhZ6GHX0mGovzZx_bFS5u-_pUkUsOA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Fri, Aug 23, 2013 at 5:07 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> Josh Berkus <josh(at)agliodbs(dot)com> writes:
>> Currently the only way to return query results to the caller is to use
>> some form of RETURN. It is 100% consistent.
>
> I don't find it consistent at all, because what that means is that the
> data is to be returned to the SQL statement that called the function.
>
> What's more, the point of any such extension needs to be to allow
> *multiple* resultsets to be returned to the client --- if you only need
> one, you can have that functionality today with plain old SELECT FROM
> myfunction(). And returning some data but continuing execution is surely
> not consistent with RETURN.

With set returning functions, RETURN QUERY etc means 'yield this data' --
which is pretty weird -- so your point only holds true for unadorned return
(not RETURN NEXT , RETURN QUERY, etc). So I guess it's hard to claim
RETURN means 'return control' though in a procedural sense. In a perfect
world, maybe a separate keyword could have been made to distinguish those
cases (e.h. YIELD QUERY), so I agree (after some reflection) with the
spirit of your point. It's not good to have principle keywords do markedly
different things.

> Basically it seems that we have two choices for how to represent this
> (hypothetical) future functionality:
>
> 1. Define SELECT without INTO as meaning return results directly to
client;
>
> 2. Invent some new syntax to do it.
>
> In a green field I think we'd want to do #2, because #1 seems rather
> error-prone and unobvious. The only real attraction of #1, IMO, is that
> it's consistent with T-SQL. But that's not a terribly strong argument
> given the many existing inconsistencies between T-SQL and plpgsql.

Very good points. I think the only compelling case for #1 that could be
made would be to improve compatibility with pl/sql -- from what I can see
Oracle has not defined the behavior (that is, in pl/sql select must have
INTO) but maybe someone could comment on that.

> BTW, what about INSERT/UPDATE/DELETE RETURNING? Do we want to let
> these execute and throw away the data? The argument that this would
> be a feature seems a lot weaker than for SELECT, because after all you
> could usually just leave off the RETURNING clause. But I'm sure somebody
> will say they want to put a function with side-effects into RETURNING
> and then ignore its output.

If we agree to relax PERFORM, those should be relaxed on the same basis.
In fact, this is conclusive evidence that PERFORM is obsolete: it hails
from the days where SELECT was the only data returning DML.

merlin

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2013-08-24 13:11:49 Re: PL/pgSQL PERFORM with CTE
Previous Message Martijn van Oosterhout 2013-08-24 12:38:36 Re: ALTER SYSTEM SET command to change postgresql.conf parameters (RE: Proposal for Allow postgresql.conf values to be changed via SQL [review])