Re: stable function called for every row? - Mailing list pgsql-general

From Tom Lane
Subject Re: stable function called for every row?
Date
Msg-id 4158.1231361526@sss.pgh.pa.us
Whole thread Raw
In response to stable function called for every row?  (Gerhard Heift <ml-postgresql-20081012-3518@gheift.de>)
List pgsql-general
Gerhard Heift <ml-postgresql-20081012-3518@gheift.de> writes:
> The function is called for every row in the table if it is stable or
> volatile and only once if it is immutable?

Yes, possibly.

> I thought it had to be called only once, if it is stable.

No.  Stable means that it is *okay* to call it only once per query,
not that that is *guaranteed* to happen.  (What it really does is give
the planner license to use an indexscan on a condition involving the
function --- an indexscan's comparison value is evaluated just once,
so it would give the wrong answers for a non-stable function.)

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: SPI_ERROR_CONNECT in plperl function
Next
From: "c k"
Date:
Subject: Fail of a return query from plpgsql function for a specific table