Re: Function call order dependency

From: pgsql(at)mohawksoft(dot)com
To: "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql(at)mohawksoft(dot)com, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Function call order dependency
Date: 2008-09-03 16:55:45
Message-ID: 46995.64.119.130.186.1220460945.squirrel@mail.mohawksoft.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> pgsql(at)mohawksoft(dot)com writes:
>> I need to perform an operation during query time and there are multiple
>> results based on the outcome. For instance: (Lets try this)
>
>> select myrank(t1.column1, t2.column2, 1) as rank,
>> myscore(t1.column1,t2.column2, 1) as score from t1, t2 where
>> myrank(t1.column1,t2.column2) > 10 order by myscore(t1.column1,
>> t2.column2, 1) desc;
>
> Why not have one function that produces multiple output columns?

I was sort of trying to make this a fairly "generic" SQL extension who's
methodology could be moved to other databases if needed. I guess multiple
columns could work. I've got some code in another extension that does
that.

>
>> Now, can I assume that in the above select statement, that each
>> permutation of t1.column1 and t2.column2 will only be evaluated once and
>> that myscore(...) and myrank(...) will all be called before the next
>> permutation is evaluated?
>
> You can assume that functions in the SELECT target list are evaluated
> exactly once per output row (at least as long as no
> SRFs-in-the-targetlist are involved). I don't think it'd be wise to
> assume anything about order of evaluation, though it's probably true
> that it's left-to-right at the moment.

But are all the items targeted in close proximity to each other BEFORE
moving on to the next row? What about the "where" clause? would that be
called out of order of the select target list? I'm doing a fairly large
amount of processing and doing it once is important.
/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2008-09-03 16:56:02 Re: Function call order dependency
Previous Message Alvaro Herrera 2008-09-03 16:55:44 Re: libpq object hooks (libpq events)