Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fIZSG-0006Zi-HM for pgsql-general@arkaria.postgresql.org; Tue, 15 May 2018 12:53:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fIZSF-0007za-Ep for pgsql-general@arkaria.postgresql.org; Tue, 15 May 2018 12:53:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fIZSD-0007zR-K4 for pgsql-general@lists.postgresql.org; Tue, 15 May 2018 12:53:23 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fIZS6-0001kF-1j for pgsql-general@lists.postgresql.org; Tue, 15 May 2018 12:53:20 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 78E0922315; Tue, 15 May 2018 08:53:12 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Tue, 15 May 2018 08:53:12 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm2; bh=thetZ7bb0pwYRkT81Fixj6/QLJCVX Uxy6lWnTmmSCCY=; b=S8gaUCulYFOo9mp9wTkSO8tH+khCWzde3QvCFtn62P415 vNwFFX2ZpdJpNxsMbzoKVXP0OTmNmD+6J0keXkhqY1PNjUdz6pHpSO6vkppIjDp2 qsPYYo0lsCBHTF/AzMUm9OCivZ/bh3MrpJPDevn5AotkNAMyAVL+1hkWsTO9kbYX N6oKOMhVJT7ZGXT2qrhLpa5G4+HCoS4pa+2oAYLGKKe/QxvmrmFE1DyHhHNiVxuY KI6x3lr/IWNaSSOT9fH5DDYGGcvLJBUe6C9v3t7fVZZfbOBmnlnOkyZcHq/9so4w IFuXVXVKcTAyp2GYX+DBic14cpbORJ71a3M5awJcg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=thetZ7 bb0pwYRkT81Fixj6/QLJCVXUxy6lWnTmmSCCY=; b=JRlT7DklJah2yHb8SRnHX5 NFZT8scZgx8tWxpquR2BCASY9B5aqC/6o62CAiK0KBTCJvXIw1OO8hyAjtLUo13W aJ/o+lcjhXmK/c9InMxnV0fJu6XPTgK+5MILtnpkLnCpMVV/1yutttjIheSxRRve 2M5Tb3TiziY8ah+YtzR9rrWsIU7mAedt+ZjBzVObGZWxTVA97gTirNZ1CO/nI/Ve UfdxfS3/MLNC84ZYVbc2iarJmP3F3nghdJJ502j8vF1ZFh1yX7S801SemboUrbml MW97/3kWMJXJIKpcIVvzSm/HLT9OVzqwNWjzK7dnZ8FbcX0T2y1OLX60KP0evFNw == X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id A8A6510256; Tue, 15 May 2018 08:53:11 -0400 (EDT) Subject: Re: Query ID Values To: pgsql-general@lists.postgresql.org, Ian Zimmerman References: <5afa3e76.1c69fb81.c680b.185d@mx.google.com> <927dc5f8-b343-c7ff-e131-17c5c3dc6814@aklaver.com> <20180515050412.s6qmx4yahzp25vgh@matica.foolinux.mooo.com> From: Adrian Klaver Message-ID: Date: Tue, 15 May 2018 05:53:10 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180515050412.s6qmx4yahzp25vgh@matica.foolinux.mooo.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/14/2018 10:04 PM, Ian Zimmerman wrote: > On 2018-05-14 21:12, Adrian Klaver wrote: > >> Because you are doing fetchall(). That is going to fetch a list of row >> tuples. Either iterate over that list or iterate over the cursor: >> >> for row in cur_p: >> print(row) >> >> For more info see: >> http://initd.org/psycopg/docs/cursor.html > > Where does that webpage say that I can use the cursor itself for > iteration? I can't find it there. (OTOH it is clearly documented for > the sqlite3 library). Results retrieval methods " Note cursor objects are iterable, so, instead of calling explicitly fetchone() in a loop, the object itself can be used: >>> cur.execute("SELECT * FROM test;") >>> for record in cur: ... print record " > > Until now, with psycopg2 I have done it like this: > > cur.execute(stmt) > results = iter(cur.fetchone, None) > for r in results: > ... > -- Adrian Klaver adrian.klaver@aklaver.com