pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Rashid Abzalov <rashid.abzalov@gmail.com>
To: pgsql-bugs@lists.postgresql.org
Subject: The statement is re-executed (performed twice) on commit if it is declared as "cursor with hold" and the cursor is not closed yet
Date: Fri, 12 Jul 2019 22:18:49 +0300
Message-ID: <CACrSCdEquRApzys++BED0=486rhAtrKnWrf4Y9mc2nhsGVUmrQ@mail.gmail.com> (raw)

The statement is re-executed on commit if it is declared as "cursor with
hold" and the cursor is not closed yet.

Tested on 11.2 and 9.6.12.

*1) DDL:*
create table test(id numeric);
create or replace function do_test() returns void
as $$
begin
  raise notice 'test executed!';
  insert into test(id) values(1);
end;
$$ LANGUAGE plpgsql VOLATILE security definer

*DML statements below are executed with autocommit = off (for example in
PgAdmin3)*

*2) DML (cursor is closed after commit):*

begin

declare exec_cur binary no scroll cursor with hold for select do_test()

fetch forward 1 from exec_cur

--close exec_cur

commit

close exec_cur



*select count(*) from test---2*

*3) DML (cursor is closed before commit):*

begin

declare exec_cur binary no scroll cursor with hold for
  select do_test()

fetch forward 1 from exec_cur

close exec_cur

commit

--close exec_cur



*select count(*) from test---1*

view thread (4+ messages)  latest in thread

Message-ID: <CACrSCdEquRApzys++BED0=486rhAtrKnWrf4Y9mc2nhsGVUmrQ@mail.gmail.com>
Permalink:  ../CACrSCdEquRApzys++BED0=486rhAtrKnWrf4Y9mc2nhsGVUmrQ@mail.gmail.com/
Also on:    postgresql.org/message-id/CACrSCdEquRApzys++BED0=486rhAtrKnWrf4Y9mc2nhsGVUmrQ@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: rashid.abzalov@gmail.com
  Subject: Re: The statement is re-executed (performed twice) on commit if it is declared as "cursor with hold" and the cursor is not closed yet
  In-Reply-To: <CACrSCdEquRApzys++BED0=486rhAtrKnWrf4Y9mc2nhsGVUmrQ@mail.gmail.com>
  References: <CACrSCdEquRApzys++BED0=486rhAtrKnWrf4Y9mc2nhsGVUmrQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox