Re: PL/pgSQL PERFORM with CTE - Mailing list pgsql-hackers

From Pavel Stehule
Subject Re: PL/pgSQL PERFORM with CTE
Date
Msg-id CAFj8pRCYHty_W6_ziijd6FqATx9NoMsGppKP5zTiwX_SyNT8qA@mail.gmail.com
Whole thread Raw
In response to Re: PL/pgSQL PERFORM with CTE  ("David E. Wheeler" <david@justatheory.com>)
Responses Re: PL/pgSQL PERFORM with CTE  ("David E. Wheeler" <david@justatheory.com>)
List pgsql-hackers



2013/8/29 David E. Wheeler <david@justatheory.com>
On Aug 29, 2013, at 1:11 PM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

> 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.

So YIELD or implement PL/PSM.

We can discussed about syntax later - now it is offtopic and it is too early - still we miss a procedures.
 

> 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.

PL/pgSQL is not PSM.

yes, I know it well - although some syntax is shared - CASE statements
 

> 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!

No reason SELECT could not work just a well.

No, originally, there was a target of compatibility with PL/SQL (more or less in some time), and PL/SQL disallow unbound SELECT.

More - PL/SQL allow a direct procedure call - so some like PERFORM is useless there.
 

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

Well, it was an aside, but points out another problem with PERFORM: It doesn't really exist. I gets replaced with SELECT internally, leading to confusing error messages. Solution: Allow SELECT instead of PERFORM.

> 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

I agree it would be nice if it didn't report SELECT there, but at least it's not *removing* anything from what you see in the source.

It was a little bit a irony. I am think now so all problems about PERFORM is based on porting  PL/SQL environment (that was a classic simplified ADA) to PostgreSQL without procedures. So PERFORM was a designed for evaluation of something like procedures - but there was nothing in this time - a VOID functions are younger.  Without PERFORM we didn't do this talk.

Still I don't think so correct solution is enabling a unbound SELECTs, but correct is a fix a PERFORM and remove a necessity to use a PERFORM for call of VOID functions.

Regards

Pavel

 

Best,

David



pgsql-hackers by date:

Previous
From: Ants Aasma
Date:
Subject: Re: Master-slave visibility order
Next
From: "David E. Wheeler"
Date:
Subject: Re: PL/pgSQL PERFORM with CTE