Re: Any reasons for 'DO' statement not returning result? - Mailing list pgsql-general

From Chris Travers
Subject Re: Any reasons for 'DO' statement not returning result?
Date
Msg-id CAKt_Zfu2rdZOwoDF9a2BJGgSjCPk=vWaWC=HQS3kwZPSGW5sFA@mail.gmail.com
Whole thread Raw
In response to Re: Any reasons for 'DO' statement not returning result?  (Merlin Moncure <mmoncure@gmail.com>)
Responses Re: Any reasons for 'DO' statement not returning result?  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
List pgsql-general


On Tue, Aug 16, 2016 at 3:11 PM, Merlin Moncure <mmoncure@gmail.com> wrote:
On Sun, Aug 14, 2016 at 5:58 AM, Chris Travers <chris.travers@gmail.com> wrote:

>>
>> All this seems to be a huge change which will definitely not appear any
>> time soon.
>
> I am willing to bet that DO $$ $$; blocks are neither planned nor
> parameterized.  And the planner needs to know what is to be returned.

The statements within a do block are absolutely planned and
parameterized.  There was some recent discussion with respect to not
planning statements except under certain conditions (in a loop
basically) to reduce memory consumption of long 'do' blocks.

Right. Which accounts for why people would expect to return results.  But I would bet the block itself is not

I mean when you run a function it is handed off to the language handler, and that is totally planner opaque (I would expect that to be the case here too).  That function may make queries, and those may be planned but because the functions can be in arbitrary languages, the planner cannot have internal knowledge of the functions or do blocks.

And since the planner usually needs to know what is returned in order to plan things like sorts, you'd have to be able to do something like:

do language plpgsql returning table (foo int, bar text) as
$$
--- insert logic here.
$$;

But at that point how much are you really saving over

CREATE  FUNCTION pg_temp.temptest() returns table (foo int, bar text) language plgsql as $$
-- insert logic here
$$; select pg_temp.temptest();

I am thinking adding a temporary keyword to functions would make a lot more sense.



merlin



--
Best Wishes,
Chris Travers

Efficito:  Hosted Accounting and ERP.  Robust and Flexible.  No vendor lock-in.

pgsql-general by date:

Previous
From: Joy Arulraj
Date:
Subject: Re: C++ port of Postgres
Next
From: James Sewell
Date:
Subject: Re: Critical failure of standby