Re: BUG #14059: BUG? function in select clause called more times when use offset

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: digoal(at)126(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #14059: BUG? function in select clause called more times when use offset
Date: 2016-04-02 14:49:26
Message-ID: 31248.1459608566@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

digoal(at)126(dot)com writes:
> postgres=# create or replace function f() returns void as $$
> declare
> begin
> raise notice 'called';
> end;
> $$ language plpgsql strict volatile;
> CREATE FUNCTION

> postgres=# select f(),* from ( values(1),(2),(3),(4),(5),(6) ) t(id) offset
> 3 limit 2;
> NOTICE: called
> NOTICE: called
> NOTICE: called
> NOTICE: called
> NOTICE: called
> f | id
> ---+----
> | 4
> | 5
> (2 rows)

> offset skip 3 tuple, but function f() called with 5 times, can we tuning
> this .
> or this is a bug?

No, it's not a bug. OFFSET only results in the skipped tuples not being
delivered to the client; it does not cause them not to be computed.

You could probably do something with a two-level select with the OFFSET
in the sub-select and the volatile function in the top level.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message 德哥 2016-04-02 16:13:05 Re: BUG #14059: BUG? function in select clause called more times when use offset
Previous Message digoal 2016-04-02 11:40:03 BUG #14059: BUG? function in select clause called more times when use offset