Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPuft-0002NL-Tn for pgsql-interfaces@arkaria.postgresql.org; Tue, 27 Jun 2017 17:53:18 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dPufs-0006rX-M0 for pgsql-interfaces@arkaria.postgresql.org; Tue, 27 Jun 2017 17:53:16 +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 1dPufs-0006rN-5o for pgsql-interfaces@postgresql.org; Tue, 27 Jun 2017 17:53:16 +0000 Received: from mail-it0-x234.google.com ([2607:f8b0:4001:c0b::234]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1dPufn-0007HN-Ng for pgsql-interfaces@postgresql.org; Tue, 27 Jun 2017 17:53:15 +0000 Received: by mail-it0-x234.google.com with SMTP id b205so19971065itg.1 for ; Tue, 27 Jun 2017 10:53:11 -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=8QBQDhadF3XyKzRRMsGKgbphFfqULRvhN94/HWJeXqs=; b=TnOAyAf6otO0xq6SAATp8fORZy6sYXsZ/BG1TTk3nDdu0GY0Gr8Ia7nJPEn5BmDIIc RKX+pg9Kvi52HOSZGxCp48pg58gXxZUOcY7VuV+fl+WZjk2OZTUKw7nkEIzSr60Ag4h1 7BFTc1QDw24ox/E16QRPXYdDwkjGkXRVwEp+Q+eD/gMKfgdmanIqY2d9te1RMCbxQeUI Qlk/AwCHkCB1GO+y+Ed0K6PdkNDLlx2yfR6slr5SsObBb9qIEjtfRlcSV7UYooNzRur8 QilQwKBz8V+9t/xHgfrdLH9CZWDMJgO+t8Tzg2oHr3qpZBwzJEKzOWCxZ7ULe7By2uC0 EXHA== 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=8QBQDhadF3XyKzRRMsGKgbphFfqULRvhN94/HWJeXqs=; b=EIErvM0KahSw98ANZzboR+ZBYrruV7vbYWAvHZSXRVsyme/Rq1lLaNWvar8htgY1en tk6lHtXRV/tosWv4dc1d4VdUgm2OCz4twe8WtNLhph/QAA1k9ecU2jkQFq16by9a4j0W UgCz8DaRrb0+ZGthyccMCMcLbj4OLFzphVcGuLYZeyuaCg/NxVzdOuM9WqetX4dzViHE g+Kf0RPEDUxPbfSAHLLzSwrybFQr6iU69GPdtdWZx7HDawR+3V3tDM9XDm+/IFpU2XVl COs1PkugKqceBgB+0LcaoOWOecn51HLJsqsXBHFlA4+3dIlKTYsqWEwC8kWbTBrABJRy uYSw== X-Gm-Message-State: AKS2vOyHg+on7jA2ZePlntwZRUx6MwJRLagpsDpRQVHWU4csAfnSPorM EO6dkH5XjoxXr73vzW9PUajBjoPp6w== X-Received: by 10.36.206.133 with SMTP id v127mr3880838itg.49.1498585989209; Tue, 27 Jun 2017 10:53:09 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.33.134 with HTTP; Tue, 27 Jun 2017 10:53:08 -0700 (PDT) In-Reply-To: References: From: Dmitry Igrishin Date: Tue, 27 Jun 2017 20:53:08 +0300 Message-ID: Subject: Re: Questions on Cursors in PostgreSQL To: Wei Shan Cc: pgsql-interfaces@postgresql.org Content-Type: multipart/alternative; boundary="94eb2c0b08008d63e30552f4bd7e" 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 --94eb2c0b08008d63e30552f4bd7e Content-Type: text/plain; charset="UTF-8" 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. --94eb2c0b08008d63e30552f4bd7e Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable


2017-06-27 20:07 GMT+03:00 Wei Shan <weishan.ang@gmail.com>= :
Hi all,
I have some questions on PostgreSQL cursors (not PL/pgSQL but t= he libpq implementation):=C2=A0

  1. What happe= ns 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 cur= sors are deallocated automatically. You should open the new cursor on recon= nect.
--94eb2c0b08008d63e30552f4bd7e--