Re: Create temporary function

Lists: pgsql-general
From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Create temporary function
Date: 2008-04-23 18:20:36
Message-ID: 480F7DF4.1000106@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

I have recently run across situations that might benefit from the
ability to create a temporary function.

One situation is where periodic processing would benefit from
server-side functions but the processing is run rarely (say monthly or
annually) and the requirements for the function may change. This is
relatively easily handled by a CREATE OR REPLACE..run..DROP FUNCTION but
CREATE TEMPORARY FUNCTION would be cleaner.

The other is where it would be nice for a client to see an isolated
individual copy of a function.

For me both of the above are minor nice-to-haves. I have no idea how
difficult this would be to implement but in the spirit of brainstorming,
I thought I'd throw it out to see if anyone else thinks it is a useful
concept.

Cheers,
Steve


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Create temporary function
Date: 2008-04-23 18:33:52
Message-ID: 15191.1208975632@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Steve Crawford <scrawford(at)pinpointresearch(dot)com> writes:
> I have recently run across situations that might benefit from the
> ability to create a temporary function.

You can do that today, as long as you don't mind schema-qualifying
uses of the function:

regression=# create function pg_temp.tfunc(int) returns int as
regression-# $$ select $1 + 1 $$ language sql;
CREATE FUNCTION
regression=# select pg_temp.tfunc(42);
tfunc
-------
43
(1 row)

Without the qualification, the function won't be found, even if
you put pg_temp into your search path explicitly. That's intentional
because of the risk of trojan horses ...

regards, tom lane


From: Steve Crawford <scrawford(at)pinpointresearch(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Create temporary function
Date: 2008-04-23 21:26:31
Message-ID: 480FA987.2060705@pinpointresearch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

Tom Lane wrote:
> Steve Crawford <scrawford(at)pinpointresearch(dot)com> writes:
>
>> I have recently run across situations that might benefit from the
>> ability to create a temporary function.
>>
>
> You can do that today, as long as you don't mind schema-qualifying
> uses of the function:
>
> regression=# create function pg_temp.tfunc(int) returns int as
> regression-# $$ select $1 + 1 $$ language sql;
>

Excellent. I've submitted this as a comment to the docs for the next
time someone googles "CREATE TEMPORARY FUNCTION".

Cheers,
Steve