Re: strange stable function behavior

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Dan Black <fireworker(at)gmail(dot)com>
Cc: pgsql general <pgsql-general(at)postgresql(dot)org>
Subject: Re: strange stable function behavior
Date: 2006-06-01 12:18:36
Message-ID: 20060601121836.GC12689@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Jun 01, 2006 at 03:09:47PM +0400, Dan Black wrote:
> Hi
> I have a stable function test.test_stable

<snip>

> But if I want to display field sid twice
>
> SELECT id, sid, sid FROM
> (SELECT *, test.test_stable(id) AS sid FROM generate_series(10, 100) AS id)
> tbl
>
> I can see that function test.test_stable executes twice with identical
> parameters

Postgres makes no special effort to avoid multiple calls of the same
function. Especially since you declared it STABLE.

> Is it bug or special feature?

Not a bug nor a special feature, just the way it is. If you put OFFSET 0
in the subquery, that will stop the expansion of the subquery, thus the
function will only be called once.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dan Black 2006-06-01 12:38:32 Re: strange stable function behavior
Previous Message Dan Black 2006-06-01 11:09:47 strange stable function behavior