how to evaluate a function only once for a query?

From: Nicolae Mihalache <mache(at)abcpages(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: how to evaluate a function only once for a query?
Date: 2002-06-20 10:40:09
Message-ID: 3D11B109.9020409@abcpages.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Gianfranco Masia - Eprom s.r.l. 2002-06-20 11:03:15 Is it possible compile Pg 7.1.3 to run under Win98?
Previous Message Henrik Steffen 2002-06-20 09:38:36 Re: Serious Crash last Friday