Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 798741FBF225 for ; Tue, 27 Dec 2011 13:47:46 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Rfb7p-00045y-Sb for pgsql-bugs@postgresql.org; Tue, 27 Dec 2011 17:47:46 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id pBRHlK8N011718; Tue, 27 Dec 2011 12:47:24 -0500 (EST) To: wcting163@163.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6360: with hold cursor, cause function executed twice and wrong results In-reply-to: References: Comments: In-reply-to wcting163@163.com message dated "Tue, 27 Dec 2011 10:11:06 +0000" Date: Tue, 27 Dec 2011 12:47:20 -0500 Message-ID: <11717.1325008040@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -3.2 (---) X-Archive-Number: 201112/229 X-Sequence-Number: 32040 wcting163@163.com writes: > The reason is that the function p_test_execute is executed twice, when > *fetch*, it is first executed, and when transaction commit, because the > cursor is a *holdable* cursor, it is executed again. Yup. I don't particularly see this as a bug. If you were to manually rewind and rescan the cursor (ie, MOVE BACKWARD ALL and re-fetch), the function would be executed multiple times too. If you don't want that to happen, the best way would be to commit the transaction immediately, not fetch some rows and then commit. regards, tom lane