Re: Anonymous code block with parameters

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>
Cc: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>, Kalyanov Dmitry <kalyanov(dot)dmitry(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Anonymous code block with parameters
Date: 2014-09-16 09:19:05
Message-ID: 20140916091905.GH23806@awork2.anarazel.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On 2014-09-16 10:24:52 +0300, Heikki Linnakangas wrote:
> On 09/16/2014 10:15 AM, Pavel Stehule wrote:
> >Why we don't introduce a temporary functions instead?
>
> You can already do that:
>
> create function pg_temp.tempfunc(i int4) returns int4 as $$ begin end; $$
> language plpgsql;

It's quite the, probably undocumented, hack though. I think it's hard to
find as a user, because it's more or less happenstance that it works. I
think we should introduce TEMPORARY properly for function, but that's a
separate patch.

> Compared to DO, you have to do extra steps to create the function, and drop
> it when you're done. And you can't use them in a hot standby, because it
> changes the catalogs. (although a better solution to that would be to make
> it work, as well as temporary tables, but that's a much bigger project).

It'd be neat, but I really don't see it happening.

> Maybe we don't need any of this, you can just use temporary function. But
> clearly someone though that DO statements are useful in general, because
> we've had temporary functions for ages and we nevertheless added the DO
> statement.

Doing a CREATE FUNCTION like that has a mighty amount of cost
associated. If you're not using the DO interactively, but
programmatically the amount of catalog and cache churn can be
problematic. So I'm in favor of adding parameters to DO.

Greetings,

Andres Freund

--
Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Amit Kapila 2014-09-16 10:13:06 Re: CRC algorithm (was Re: [REVIEW] Re: Compression of full-page-writes)
Previous Message Pavel Stehule 2014-09-16 08:21:02 Re: Anonymous code block with parameters