Re: functions: stable/volatile - Mailing list pgsql-general

From Rafal Pietrak
Subject Re: functions: stable/volatile
Date
Msg-id 1164063582.5632.59.camel@zorro.isa-geek.com
Whole thread Raw
In response to Re: functions: stable/volatile  (Tomasz Ostrowski <tometzky@batory.org.pl>)
List pgsql-general
Hmmm. Definitly better then my code.
1. does not use the spurious tool_table
2. is surely safe on high traffic and against unintencialnal tool_table
littering.

yet, forces us to write down "SELECT" when we actually mean "UPDATE".
This is sort of 'source code obfuscation' - it's not a very good
practice, but only an aestetics issue. I can live with that.

So, thenx for the hint. I'll surely use it.

-R


On Mon, 2006-11-20 at 16:59 +0100, Tomasz Ostrowski wrote:
> On Mon, 20 Nov 2006, Rafal Pietrak wrote:
>
> > The most obvious construct I'd use is:
> >         UPDATE my_table set filed=newvalue WHERE
> >                  my_function(input)=my_table.selector_field;
> > but it's useless, since the function would have been be evaluated for
> > every row of the table.
>
> -- Not tested
>
> create function update_my_table(newvalue, input)
>     returns void
>     volatile
>     language plpgsql
> as $$
> declare
>     selector selector_field_type;
> begin
>     selector := my_function(input);
>     update my_table set filed=newvalue
>         where my_table.selector_field=selector;
> end;
> $$;
>
> -- and then
>
> select update_my_table(newvalue, input);
>
> -- Not tested.
>
> Regards
> Tometzky

pgsql-general by date:

Previous
From: Casey Duncan
Date:
Subject: Re: More on unique vs distinct
Next
From: "Joshua D. Drake"
Date:
Subject: Re: More on unique vs distinct