X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 6AC2DD1B4F1 for ; Wed, 17 Sep 2003 21:13:45 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 06788-01 for ; Wed, 17 Sep 2003 18:13:16 -0300 (ADT) Received: from sss.pgh.pa.us (unknown [192.204.191.242]) by svr1.postgresql.org (Postfix) with ESMTP id ADA73D1B506 for ; Wed, 17 Sep 2003 18:13:13 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.12.9/8.12.9) with ESMTP id h8HLDDpr005921; Wed, 17 Sep 2003 17:13:13 -0400 (EDT) To: Tomasz Myrta Cc: Lista dyskusyjna pgsql-sql Subject: Re: cursors in plpgsql In-reply-to: <3F68C810.6020401@klaster.net> References: <3F68C810.6020401@klaster.net> Comments: In-reply-to Tomasz Myrta message dated "Wed, 17 Sep 2003 22:46:08 +0200" Date: Wed, 17 Sep 2003 17:13:13 -0400 Message-ID: <5920.1063833193@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/169 X-Sequence-Number: 15147 Tomasz Myrta writes: > I wanted to use some select result several times in pl/pgsql function. > Neither move backward 10000 in test; > nor > execute ''move backward 10000 in test''; > doesn't work. Releases before 7.4 are spotty about supporting backwards scan of complex queries --- if you have a join or aggregate in the query, it likely won't work, yielding either strange errors or wrong answers. It will work if the top plan node in the query is a SORT, though, so a possible workaround is to add an explicit ORDER BY to the cursor's query. (You will need to do some investigation with EXPLAIN to make sure you are getting a suitable plan for the cursor.) Or try 7.4 beta ... regards, tom lane