Re: PL/pgSQL PERFORM with CTE

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

2013/8/28 Robert Haas <robertmhaas(at)gmail(dot)com>

> On Tue, Aug 27, 2013 at 6:10 PM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
> wrote:
> > what is magical?
> >
> > Stored procedures - we talk about this technology was a originally simple
> > script moved from client side to server side.
> >
> > so if I write on client side
> >
> > BEGIN;
> > SELECT 1,2;
> > SELECT 2;
> > SELECT 3,4;
> > END;
> >
> > then I expect results
> >
> > 1,2
> > 2
> > 3,4
>
> The biggest problem with this idea is that people will do it by
> accident with unacceptable frequency. During the decade or so I
> worked as a web programmer, I made this mistake a number of times, and
> judging by the comments on this thread, Josh Berkus has made it with
> some regularity as well. If experienced PostgreSQL hackers who know
> the system inside and out make such mistakes with some regularity, I
> think we can anticipate that novices will make them even more often.
>
> And, TBH, as others have said here, I find the requirement to use
> PERFORM rather than SELECT rather ridiculous. The clash with CTEs has
> been there since we added CTEs, and I've hit it more than once. Yeah,
> you can work around it, but it's annoying. And why annoy people? So
> +1 from me for de-requiring the use of PERFORM (though I think we
> should definitely continue to accept that syntax, for backward
> compatibility).
>
> At the end of the day, procedural languages in PostgreSQL are
> pluggable. So if we someday have the ability to return extra result
> sets on the fly, and if Pavel doesn't like the syntax we choose to use
> in PL/pgsql, he can (and, given previous history, very possibly will!)
> publish his own PL with different syntax. But I'm with the crowd that
> says that's not the right decision for PL/pgsql.
>

I cannot to say what is good design for PL/pgSQL - only I feel so some
variant of RETURN statement is not good, because semantic is significantly
different. And I see a increasing inconsistency between a original ADA and
PL/pgSQL.

Sure, When I am thinking about PSM, I am thinking about T-SQL syntax, but
there is little bit simpler situation - there is a precedent in PSM
implementation in MySQL and some other new databases.

>
> Also, even if we did adopt Pavel's proposed meaning for "SELECT 1,2",
> we still have a problem to solve, which is what the user should write
> when they want to run a query and ignore the results. The PERFORM
> solution was adequate at a time when all select queries started with
> SELECT, but now they can start with WITH or VALUES or TABLE as well,
> and while VALUES and TABLE may be ignorable, WITH certainly isn't.
> Requiring people to use silly workarounds like selecting into an
> otherwise-pointless dummy variable is not cool. If we reserve the
> undecorated-SELECT syntax to mean something else, then we've got to
> come up with some other way of solving David's original problem, and I
> don't think there are going to be many elegant options.
>
> Finally, I'd like to note that it's been longstanding frustration of
> mine that the PERFORM->SELECT transformation is leaky. For example,
> consider:
>
> rhaas=# do $$begin perform amazingly_well(); end;$$;
> ERROR: function amazingly_well() does not exist
> LINE 1: SELECT amazingly_well()
>

I am thinking, so we are near a merit of problem - if I understand well, a
PERFORM was originally designed instead a CALL statement. Due
implementation it was used for some other SQL calls too.

Origin PL/SQL doesn't allow SELECT without INTO.

your example is good and important, because almost all described issues are
related to unsuccessfully solved or a missing procedures.

so main problem is a impossibility to write

BEGIN
CALL fce()

or

BEGIN
fce();

A workaround in Postgres is PERFORM - and I really has nothing again to
remove PERFORM for start of VOID functions!

A unhelpful error message has zero relevant to topic - just almost all in
PL/pgSQL is SELECT.

Do you would to remove a ":=" statement too?

postgres=# do $$declare x int; begin x := notexisting(10); end; $$ ;
ERROR: function notexisting(integer) does not exist
LINE 1: SELECT notexisting(10)
^
HINT: No function matches the given name and argument types. You might
need to add explicit type casts.
QUERY: SELECT notexisting(10)
CONTEXT: PL/pgSQL function inline_code_block line 1 at assignment
Time: 148.760 ms

Regards

Pavel

-
> Robert Haas
> EnterpriseDB: http://www.enterprisedb.com
> The Enterprise PostgreSQL Company
>

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2013-08-29 20:26:18 Re: Variadic aggregates vs. project policy
Previous Message Tom Lane 2013-08-29 19:55:13 Variadic aggregates vs. project policy