Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1amMvj-0003Xq-3K for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Apr 2016 14:53:39 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1amMvi-0007Y9-M9 for pgsql-bugs@arkaria.postgresql.org; Sat, 02 Apr 2016 14:53:38 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1amMv6-0006qo-4n for pgsql-bugs@postgresql.org; Sat, 02 Apr 2016 14:53:00 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1amMuz-0007Bl-Ik for pgsql-bugs@postgresql.org; Sat, 02 Apr 2016 14:52:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id u32EnQC1031249; Sat, 2 Apr 2016 10:49:26 -0400 From: Tom Lane To: digoal@126.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #14059: BUG? function in select clause called more times when use offset In-reply-to: <20160402114003.4804.46227@wrigleys.postgresql.org> References: <20160402114003.4804.46227@wrigleys.postgresql.org> Comments: In-reply-to digoal@126.com message dated "Sat, 02 Apr 2016 11:40:03 -0000" Date: Sat, 02 Apr 2016 10:49:26 -0400 Message-ID: <31248.1459608566@sss.pgh.pa.us> X-Pg-Spam-Score: -2.9 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org digoal@126.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 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs