Re: Functions as first-class values

From: Merlin Moncure <mmoncure(at)gmail(dot)com>
To: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
Cc: Jon Smark <jon(dot)smark(at)yahoo(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Functions as first-class values
Date: 2011-04-06 15:11:39
Message-ID: BANLkTinMw6+Zkh7-QOt2=Y_LFZ7z3b0LKQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Apr 6, 2011 at 9:10 AM, Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com> wrote:
> Hello
>
> 2011/4/6 Jon Smark <jon(dot)smark(at)yahoo(dot)com>:
>> Hi,
>>
>> Is there support in PL/pgSQL for treating functions as first-class values?
>> Consider the pseudo-code simple example below, which illustrates how this
>> feature can be useful.  I reckon that this behaviour can be emulated using
>> EXECUTE, but I suspect there are serious performance penalties.
>> Your thoughts?
>>
>> Thanks in advance!
>> Jon
>>
>>
>> CREATE FUNCTION f1 (int) RETURNS boolean ...
>> CREATE FUNCTION f2 (int) RETURNS boolean ...
>> CREATE FUNCTION f3 (int) RETURNS boolean ...
>>
>> CREATE FUNCTION do_stuff ...
>> BEGIN
>>        CASE cond
>>                WHEN 'a' THEN func := f1;
>>                WHEN 'b' THEN func := f2;
>>                WHEN 'c' THEN func := f3;
>>        END CASE
>>
>>        SELECT * FROM foobar WHERE func (foobar.age);
>> END;
>>
>
> no it isn't possible.

it can be done with a small C wrapper though. see archives.

merlin

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jerry Sievers 2011-04-06 15:15:31 Re: Auto Adjust Age
Previous Message Michael Glaesemann 2011-04-06 15:10:18 Re: forums.postgresql.com.au