Re: Problem with cursor - Mailing list pgsql-general

From Tom Lane
Subject Re: Problem with cursor
Date
Msg-id 26031.1056211783@sss.pgh.pa.us
Whole thread Raw
In response to Problem with cursor  ("Frank Millman" <frank@chagford.com>)
List pgsql-general
"Frank Millman" <frank@chagford.com> writes:
> [ this doesn't work: ]
> begin ;
> declare fm scroll cursor for select a.CompanyId, b.CompanyName
>   from SysUsersCompanies a, SysCompanies b
>   where UserId =3D 'Greer' and a.CompanyId =3D b.CompanyId
>   order by a.CompanyId ;
> move 1 in fm ;
> fetch next from fm ;
> move -2 in fm ;
> fetch next from fm ;

Yeah, there are known problems with running complex queries backwards
in existing releases.  Some plan types support this, and some don't
--- in particular, mergejoin doesn't handle it, which very likely is
the plan type you are getting here.

There is a fix in place for 7.4 but that won't help you today.  The only
workaround I can suggest is to force the system to adopt a plan that
involves a top-level sort.  You could probably do that by adding some
additional terms to the ORDER BY clause, but some experimentation with
EXPLAIN will be called for.

            regards, tom lane

pgsql-general by date:

Previous
From: The Hermit Hacker
Date:
Subject: Re: [pgsql-advocacy] MySQL gets $19.5 MM
Next
From: Josh Berkus
Date:
Subject: Re: [pgsql-advocacy] Governance WAS: MySQL gets $19.5 MM