Re: STABLE functions - Mailing list pgsql-hackers

From Joachim Wieland
Subject Re: STABLE functions
Date
Msg-id 20030425145007.GA26172@mcknight.de
Whole thread Raw
In response to Re: STABLE functions  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: STABLE functions  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Hi Tom,

On Fri, Apr 25, 2003 at 10:01:44AM -0400, Tom Lane wrote:
> > I thought that this function is only executed once when declared as
> > STABLE,

> You are mistaken.

> If you'd declared it IMMUTABLE, then it would get constant-folded, but
> that may or may not be suitable for your purpose.

The function in question is not IMMUTABLE :-( It depends on database
lookups but won't change its results within one transaction.

Quotation from the docs:

| STABLE indicates that within a single table scan the function will
| consistently return the same result for the same argument values, but
| that ist result could change across SQL statements.

So why is a
 SELECT ... FROM table WHERE col = f(...)

(with a STABLE function f) not a "single table scan" or why does
PostgreSQL re-calculate the value of f() here for every row?


Thanks a lot,
Joachim

-- 
*****PGP key available - send e-mail request*****
Due to circumstances beyond your control, you are master of your fate
and captain of your soul.



pgsql-hackers by date:

Previous
From: Bruce Momjian
Date:
Subject: Re: close() vs. closesocket()
Next
From: Tom Lane
Date:
Subject: Re: STABLE functions