Received: from localhost (unknown [200.46.204.184]) by postgresql.org (Postfix) with ESMTP id DEFC79FC9A0 for ; Thu, 1 Nov 2007 17:48:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 28795-01-4 for ; Thu, 1 Nov 2007 17:48:10 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from mu-out-0910.google.com (mu-out-0910.google.com [209.85.134.185]) by postgresql.org (Postfix) with ESMTP id 455269FCBD4 for ; Thu, 1 Nov 2007 17:19:45 -0300 (ADT) Received: by mu-out-0910.google.com with SMTP id i10so543237mue for ; Thu, 01 Nov 2007 13:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; bh=rjyoP1RZ9i++7mt+wRZ6l5DvaQUFrs6s4tCU1buJMSU=; b=ax4XEP+zMzj+ZQf5zQPXTtY6ib8tfWWk5OtY0VDTS1TsNWm95eHdEwQqIG867CK+usI+ol4H79QKe3BvAvtdHAOVjdmEW7MfTXO3ne+xX/vb63MSCH+DG2umaZiD1Aben+HwrM8kAGqMxFHfEnwF2Iu68Bk8RIr5PDJoREF8yKE= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:mime-version:content-type:content-transfer-encoding:content-disposition; b=PWnZer6EwLiVm/5hvz5a82lECjlYMpGLDMoQb43k5A213aEbjtBOWmVYvCAGXih+L0zuHKX76DLJLImFZyoVHEKCCT0xcaPGriMR5qJXsW1WFBNFb4/b/ENwa58412pFFBCTSBUUM3kUusCq52Mbf6OoQJm97bycpQ3Fb9Y9Zmw= Received: by 10.82.160.19 with SMTP id i19mr2057953bue.1193948384182; Thu, 01 Nov 2007 13:19:44 -0700 (PDT) Received: by 10.82.170.3 with HTTP; Thu, 1 Nov 2007 13:19:44 -0700 (PDT) Message-ID: <758d5e7f0711011319t5e752dsad6481d1427a46ff@mail.gmail.com> Date: Thu, 1 Nov 2007 21:19:44 +0100 From: "Dawid Kuroczko" To: "Postgres General" Subject: Scrolling cursors in PL/PgSQL Cc: pgsql-sql MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/33 X-Sequence-Number: 123029 Hello. Is there a way to scroll a cursor from within PL/PgSQL? I tried EXECUTE, but: ERROR: cannot manipulate cursors directly in PL/pgSQL HINT: Use PL/pgSQL's cursor features instead. The idea would be that PL/pgsql function would look through (all) query results, then rewind the cursor and finally return it. My fellow developers have created a function which run the (complex) query twice (first a count(*) on the result set, then return the row count and cursor to the results. Then they created a version which uses temporary table as a placeholder for the query results, and results count and a pointer to select * from tmp_table. Now I imagined a function which would open the cursor, MOVE FORWARD ALL, then MOVE ABSOLUTE 0; and return count and a cursor, yet it seems it won't work. Any other idea how to efficiently solve such a problem? Regards, Dawid