Received: from localhost (unknown [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 497F79FC607 for ; Thu, 1 Nov 2007 18:23:46 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 26527-01-4 for ; Thu, 1 Nov 2007 18:23:42 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from wx-out-0506.google.com (wx-out-0506.google.com [66.249.82.236]) by postgresql.org (Postfix) with ESMTP id 17E9D9FCA6E for ; Thu, 1 Nov 2007 18:05:39 -0300 (ADT) Received: by wx-out-0506.google.com with SMTP id r21so544542wxc for ; Thu, 01 Nov 2007 14:05:38 -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:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; bh=BdrLKx3JTTWy0oQUOThkW1+O+BAuOVPJ+m1wxnVctfc=; b=m0PRnAhq38EZ4qjBfzpvB7NZcHv6bAa8W2fgBZPNOyrQvPf+QIPBALIYhG+6frzj+2wb6tvOpImj554ZC0wa+Pp8be5KP2RMnZsTQ5RnFJ0Ag49oiH9aWKLblQT8dsCtdQFPiplJ7zemKYoZNR3wcNnY183VUGdz+ss1kA0KZvk= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=aAM7cbUFN1cDTHpHjonVt81QeuMgAr0fZoBofuB6TKqJlGgPiFN/+pWUp1drpQh64xP98sgL11rVWK7mgsge+7NiFzX6kYk1Uy4CvGcSJm9JDlZ6llV0rzMb+DdwY4W+tC3yX7P5LNwFUe+MZAO794qgGW37j/kWwn6pFWNDdzk= Received: by 10.90.115.9 with SMTP id n9mr771075agc.1193951138850; Thu, 01 Nov 2007 14:05:38 -0700 (PDT) Received: by 10.90.32.3 with HTTP; Thu, 1 Nov 2007 14:05:38 -0700 (PDT) Message-ID: <162867790711011405x22b205afj9b89645e4f6a2174@mail.gmail.com> Date: Thu, 1 Nov 2007 22:05:38 +0100 From: "Pavel Stehule" To: "Dawid Kuroczko" Subject: Re: Scrolling cursors in PL/PgSQL Cc: "Postgres General" , pgsql-sql In-Reply-To: <758d5e7f0711011319t5e752dsad6481d1427a46ff@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <758d5e7f0711011319t5e752dsad6481d1427a46ff@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/41 X-Sequence-Number: 123037 On 01/11/2007, Dawid Kuroczko wrote: > 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? > Hello PostgreSQL 8.3 allows scrollable cursors in plpgsql Regards Pavel Stehule