Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dSJaS-0008RA-JR for pgsql-interfaces@arkaria.postgresql.org; Tue, 04 Jul 2017 08:53:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dSJaR-0000GQ-TL for pgsql-interfaces@arkaria.postgresql.org; Tue, 04 Jul 2017 08:53:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dSJa6-00081F-1f for pgsql-interfaces@postgresql.org; Tue, 04 Jul 2017 08:53:14 +0000 Received: from mail-wr0-x232.google.com ([2a00:1450:400c:c0c::232]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dSJa2-0005RQ-QV for pgsql-interfaces@postgresql.org; Tue, 04 Jul 2017 08:53:12 +0000 Received: by mail-wr0-x232.google.com with SMTP id r103so245588149wrb.0 for ; Tue, 04 Jul 2017 01:53:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=hG1viXhobjr3ulDWaHNH/0Kom3JsFsK5fb9TEYnzLtQ=; b=sgXtDTkB52o1nbCs9OrYy0VYnoDOtXounCM7SIAVsKxuYYqCXY8fQapxj24ciNuzkn EG4dVQySSlLOblZfSHeQ4owEikS1itin5Zm+o6oIHxJzQZaZCaVE9Cxf/oKOlJJg1Gb0 U50QyjNE9lbtx+/7yuqtRrbudIHtaPMFrcgRxXvrlbwlw4sC8BIuY9vBXpwhLrVbi4YL 480kZ6+YD9eDLky/+y3AL+0FfMtyZJpeK0lIvaDZIrvr2sGfmB+Lt3YOpvZZFFeFPXBo l/jspvMyrBHWuvGs9uyvYDKjbFUu0gmyfrwP6jlfTxQ0qEyZM1sCN1jT6Bo1B5DQYNwW jgdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=hG1viXhobjr3ulDWaHNH/0Kom3JsFsK5fb9TEYnzLtQ=; b=Xfe46ChMTB0mJbKkmeJGtG07NVvmb5zWGvT569UX/jPWOYq5uKVC73hVRSyvVwy39u aMqgVRl/H2UJIiUMPjmwQbzR3cj1/hXBsyEzkIfgsV1Z4jWq4KdzDKHVviEFEWZ/cAFb zZMjPLosKPeJL8e0kIxH3F8kNwHqleBGFWv/V8SMQgnJAO5bh7ZOCka0EVzNGRZDAYGQ VMQUP0NNZgmoTW8EWp/1GHMYmEpF7t/yqy6BUN4ptT/XaynIk2aaoYq2n/9UlaAKgoEM RqsZlW5dn4VBIXAqfieddOBr0OtwjIcE/UWz1To/HKXWuZ+1apCe5b2Vv7ENM9wns3mG E/gQ== X-Gm-Message-State: AIVw113CxpT8qHMPJadhy4lVLVfgfmCq6A9EoZTqMkR1JJL6qja8FPIr q2Rayawac5i3Pxu1OBdQvrGsSj/65w== X-Received: by 10.223.170.138 with SMTP id h10mr4000350wrc.153.1499158389375; Tue, 04 Jul 2017 01:53:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.146.129 with HTTP; Tue, 4 Jul 2017 01:53:08 -0700 (PDT) Received: by 10.223.146.129 with HTTP; Tue, 4 Jul 2017 01:53:08 -0700 (PDT) In-Reply-To: References: From: Wei Shan Date: Tue, 4 Jul 2017 09:53:08 +0100 Message-ID: Subject: Re: Questions on Cursors in PostgreSQL To: Dmitry Igrishin Cc: pgsql-interfaces@postgresql.org Content-Type: multipart/alternative; boundary="94eb2c1b6ec442c64805537a03d7" List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-interfaces Precedence: bulk Sender: pgsql-interfaces-owner@postgresql.org --94eb2c1b6ec442c64805537a03d7 Content-Type: text/plain; charset="UTF-8" Thanks a lot! On 27 Jun 2017 18:53, "Dmitry Igrishin" wrote: 2017-06-27 20:07 GMT+03:00 Wei Shan : > Hi all, > > I have some questions on PostgreSQL cursors (not PL/pgSQL but the libpq > implementation): > > > 1. What happens when my cursor hit the end of the table? Does it close > automatically? I suppose if I declare it as a SCROLLABLE cursor, it should > not close at all. > > The lifetime of cursors created by the DECLARE ... SQL command longs until the end of the session, or until it explicitly closed by either CLOSE ... or DISCARD SQL commands. > > 1. If I have declared a cursor and the session got disconnected, can I > reattach back to the cursor if I know the cursor name? I believe this is > not possible but I'm not very sure. > > When session ends all cursors are deallocated automatically. You should open the new cursor on reconnect. --94eb2c1b6ec442c64805537a03d7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Thanks a lot!




On 27 Jun 2017 18:53, "Dmitry Igrishin" <dmitigr@gmail.com> wrote:

=
2017-06-27 20:07 = GMT+03:00 Wei Shan <weishan.ang@gmail.com>:
Hi all,

I have so= me questions on PostgreSQL cursors (not PL/pgSQL but the libpq implementati= on):=C2=A0

  1. What happens when my cursor hit= the end of the table? Does it close automatically? I suppose if I declare = it as a SCROLLABLE cursor, it should not close at all.
The lifetime of cursors created by the DECLARE ...= SQL command longs until the end of the session, or until it explicitly clo= sed by either CLOSE ... or DISCARD SQL commands.
  1. If I hav= e declared a cursor and the session got disconnected, can I reattach back t= o the cursor if I know the cursor name? I believe this is not possible but = I'm not very sure.
When se= ssion ends all cursors are deallocated automatically. You should open the n= ew cursor on reconnect.

--94eb2c1b6ec442c64805537a03d7--