Re: how to make an SQL UPDATE from record returning function - Mailing list pgsql-general

From Thomas Kellerer
Subject Re: how to make an SQL UPDATE from record returning function
Date
Msg-id jn5u3q$mhf$1@dough.gmane.org
Whole thread Raw
In response to how to make an SQL UPDATE from record returning function  (Rafal Pietrak <rafal@zorro.isa-geek.com>)
Responses Re: how to make an SQL UPDATE from record returning function
List pgsql-general
Rafal Pietrak, 24.04.2012 09:02:
> Hi all,
>
> Recently I have fell onto a multicolumn update problem, earlier
> discussed here:
>
> http://postgresql.1045698.n5.nabble.com/UPDATE-of-several-columns-using-SELECT-statement-td1916045.html
>
> But in my case, subselect does not help, since in my case, new values
> for a row I get from an output of record returning function ... and real
> problem is that this function is quite expensive to run.
>
> I currently check this on pg v8.4, and it doesn't work just like in that
> 2009. I was wondering if the 9th release changes anything, or may be
> there is a workaround?
>
> I actually try to:
>
> UPDATE my_table SET (col1,col2) = my_function(col3, col4, ...);
>
> And running the function twice:
>
> UPDATE my_table SET col1 = my_func1(col3, col4, ...), col2 =
> my_func2(col3, col4, ...);
>
> is not an option, since the function is *very* expensive (multiple join
> of large tables - inventories, history, etc).
>
> Is there a syntax workaround that I could possibly use to get the effect
> of launching my_function just once?

With 9.1 you could probably achieve this using a writeable CTE.

Although I have to admit I don't really understand what your function is returning.
Does the function return a result set or scalar values?




pgsql-general by date:

Previous
From: Rafal Pietrak
Date:
Subject: Re: how to make an SQL UPDATE from record returning function
Next
From: Andrew Dunstan
Date:
Subject: Re: [HACKERS] Namespace of array of user defined types is confused by the parser in insert?