Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hm14Z-0003fw-CQ for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jul 2019 19:19:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hm14X-00082E-Ha for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Jul 2019 19:19:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hm14X-00080e-4T for pgsql-bugs@lists.postgresql.org; Fri, 12 Jul 2019 19:19:09 +0000 Received: from mail-lj1-x244.google.com ([2a00:1450:4864:20::244]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hm14T-0001pR-Tg for pgsql-bugs@lists.postgresql.org; Fri, 12 Jul 2019 19:19:08 +0000 Received: by mail-lj1-x244.google.com with SMTP id m23so10321719lje.12 for ; Fri, 12 Jul 2019 12:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=rR+3NotYoK6VrBzco9ys+fwnuJN7HAs9HG0ay+wDmeg=; b=HCT8mC2/0BU6hXbaSALufHk7kUS8m8M2UXemYaIAUVWhG6FAubLgBEbDGYTq0pO9dZ R/AwKh5ETM9bHw0zmeuZ877yC1xYsuC0LG6nwLHdZuu/3RMMP3Tp8Gd0OoqFgQ59M2Ws miHve6otQHO48LQrS5ZFRovxJaJ1TQrprDLvtN3sIg++WeJ9Cfmtk4tvhwGeTWFkR0Zj UmdjXwPajjel0mbv7z7oJmDWQF0meBXtGafZLvciWrANGzxcmvAH248p2plgSafoJSiJ aQht69k+zZWGXjuIk2R8UjdkgpVOqR79N1x+Fc5tFYKmvUcc/D9toL0jrzE5gazHXkan Tu6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=rR+3NotYoK6VrBzco9ys+fwnuJN7HAs9HG0ay+wDmeg=; b=BUSsc41rJuzqFslv7R12h6BauPtazG0eC2jyaS87b4Z9vQHjZifh9psXBOqOlv0JnU EE5wvYCJt0H9DEmyexMLHIJSy4kszgfjSG8vu1yVhmT5hmFiP+p90IbcZioU83gQ5pOi vtlh48H8JBjyNEOpl85T7GVGKf43Dnb/sNWfC57VuNIfZLBouqOMHCRC/K/cwRQREWam ivB0uhrn1iGL4eR0MAW1aI2UI9efwg/rIYCuZ/MzP95Jm3OMDRX7ky2BqsrgPLV83Et1 JsQ0Lv3H4Nr1tPahG4I7PLVmU2QbrdJb4MTslBKPy/o/C0RObvouS6Q9/D0T2UmX3LtD vLEQ== X-Gm-Message-State: APjAAAXfgGKMXuX/c+RDrG9pofIOTcXzpVUTlBkZV4p9GTcqt6Hht/0f C8DrjwudO+Bxtt9AuLEuxIBPcMH5kqWfN3R65zIMw6K0 X-Google-Smtp-Source: APXvYqxIfITi0eaLK8QAHq1GPIG/drmX4OdAHHRaOBNwepc8OjwWu9vjdAcH9gk6u2SwXu9ta4DVh/6eaGWXMCcPhhA= X-Received: by 2002:a2e:63cd:: with SMTP id s74mr6736878lje.164.1562959143612; Fri, 12 Jul 2019 12:19:03 -0700 (PDT) MIME-Version: 1.0 From: Rashid Abzalov Date: Fri, 12 Jul 2019 22:18:49 +0300 Message-ID: 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 To: pgsql-bugs@lists.postgresql.org Content-Type: multipart/alternative; boundary="0000000000008db54d058d80c8c0" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --0000000000008db54d058d80c8c0 Content-Type: text/plain; charset="UTF-8" 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* --0000000000008db54d058d80c8c0 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
The statement is re-executed on commit if it is declared a= s "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 voi= d
as $$
begin
=C2=A0 raise notice 'test executed!';
=C2= =A0 insert into test(id) values(1);
end;
$$ LANGUAGE plpgsql VOLATILE= security definer

DML statements below are executed with autocomm= it =3D off (for example in PgAdmin3)

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

begin

declare exec_cur binary no s= croll cursor with hold for=C2=A0select do_test()

fetch forward 1 fro= m exec_cur

--close exec_cur

commit

close exec_cur
<= br>select count(*) from test
---
2


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

begin

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

fetch forward= 1 from exec_cur

close exec_cur

commit

--close exec_cu= r

select count(*) from test
---
1

--0000000000008db54d058d80c8c0--