Skip site navigation (1) Skip section navigation (2)

with hold cursor, cause function execute twice and wrong result

From: wcting163 <wcting163(at)163(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: with hold cursor, cause function execute twice and wrong result
Date: 2011-12-28 02:09:20
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-bugs
postgres=# select version();
 PostgreSQL 9.0alpha5 on x86_64-unknown-linux-gnu, compiled by GCC gcc (GCC) 4.1.2 20080704 (Asianux 3.0 4.1.2-44), 64-b
create table test_execute(id int,name varchar(40));
insert into test_execute values(1,'jack');
create or replace function p_test_execute() returns void
        raise notice 'hello world';
        update test_execute set id=id*2;
$$ LANGUAGE plpgsql;
declare JDBC_CURS_1 cursor with hold for select p_test_execute() from test_execute;
fetch 50 from JDBC_CURS_1;
NOTICE:  hello world
NOTICE:  hello world
select * from test_execute;
 id | name
  4 | jack
I expect id = 2, but it is **4** instead,
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.
I read the code, for holdable cursor, when commit, following call will execute:
Is *ExecutorRewind* necessary, is it the root of this bug?
Does *ExecutorRewind* cause plan re-execute?


pgsql-bugs by date

Next:From: wcting163Date: 2011-12-28 02:44:39
Subject: Re: BUG #6360: with hold cursor, cause function executed twice and wrong results
Previous:From: Phil SorberDate: 2011-12-27 21:43:54
Subject: Re: converting between infinity timestamp and float8 (epoch)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group