Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id 0008EB5DBC7 for ; Sat, 15 Oct 2011 20:29:07 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 97411-09 for ; Sat, 15 Oct 2011 23:29:00 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.8.0-rc2 Received: from wulczer.org (wulczer.org [109.74.195.157]) by mail.postgresql.org (Postfix) with ESMTP id 31C76B5DBC4 for ; Sat, 15 Oct 2011 20:29:00 -0300 (ADT) Received: from [85.59.228.11] (helo=[10.0.0.102]) by wulczer.org with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1RFDez-0001ZU-0Q for pgsql-hackers@postgresql.org; Sat, 15 Oct 2011 23:28:59 +0000 Message-ID: <4E9A1738.6090108@wulczer.org> Date: Sun, 16 Oct 2011 01:28:56 +0200 From: =?UTF-8?B?SmFuIFVyYmHFhHNraQ==?= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:5.0) Gecko/20110624 Thunderbird/5.0 MIME-Version: 1.0 To: Postgres - Hackers Subject: plpython SPI cursors X-Enigmail-Version: 1.2 Content-Type: multipart/mixed; boundary="------------060501080101020408060607" X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.404 tagged_above=-5 required=5 tests=BAYES_00=-1.9, RP_MATCHES_RCVD=-0.504 X-Spam-Level: X-Archive-Number: 201110/904 X-Sequence-Number: 196710 This is a multi-part message in MIME format. --------------060501080101020408060607 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi, attached is a patch implementing the usage of SPI cursors in PL/Python. Currently when trying to process a large table in PL/Python you have slurp it all into memory (that's what plpy.execute does). This patch allows reading the result set in smaller chunks, using a SPI cursor behind the scenes. Example usage: cursor = plpy.cursor("select a, b from hugetable") for row in cursor: plpy.info("a is %s and b is %s" % (row['a'], row['b'])) The patch itself is simple, but there's a lot of boilerplate dedicated to opening a subtransaction and handling prepared plans. I'd like to do some refactoring of they way PL/Python uses SPI to reduce the amount of boilerplate needed, but that'll come as a separate patch (just before the patch to split plpython.c in smaller chunks). This feature has been sponsored by Nomao. Cheers, Jan PS: I already added it to the November CF. J --------------060501080101020408060607 Content-Type: text/x-diff; name="0001-Add-cursor-support-to-plpythonu.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-Add-cursor-support-to-plpythonu.patch" --------------060501080101020408060607--