how to evaluate a function only once for a query? - Mailing list pgsql-general

From Nicolae Mihalache
Subject how to evaluate a function only once for a query?
Date
Msg-id 3D11B109.9020409@abcpages.com
Whole thread Raw
Responses Re: how to evaluate a function only once for a query?  (Tom Lane <tgl@sss.pgh.pa.us>)
Re: how to evaluate a function only once for a query?  (Richard Huxton <dev@archonet.com>)
List pgsql-general
Hello!

I'm tring to use postgesql functions written in pgtcl.
I've created a function timevalue(text) that returns a timestamp as
result. The function works just fine.
However, when I do a query like:
"select * from mytable where time<timevalue('something')" I see that my
function is evaluated once for each row in mytable. The problem is that
it will return each time the same value (because the argument is
constant) and takes a lot of time to execute because my function is slow.
The ideal behaviour  would be that the function is called only once when
the query is interpreted and then the value is used as a constant.
Is there any possibility to make it behave like that?
I know that I can make a "select timevalue('something')" before and then
invoke my query with the result, but I'd like to have only one query for
this.

Thanks,
Nicolae Mihalache


pgsql-general by date:

Previous
From: "Henrik Steffen"
Date:
Subject: Re: Serious Crash last Friday
Next
From: Jan Wieck
Date:
Subject: Re: circular REFERENCES