order by when using cursors - Mailing list pgsql-sql

From Patrick Scharrenberg
Subject order by when using cursors
Date
Msg-id 4858A503.4030804@web.de
Whole thread Raw
Responses Re: order by when using cursors  ("Pavel Stehule" <pavel.stehule@gmail.com>)
List pgsql-sql
Hi!

I  did some experiments with cursors and found that my data doesn't get
sorted by the "order by"-statement.

Here is what I did:

----------------

CREATE TABLE ta ( a integer NOT NULL, b integer NOT NULL
);

insert into ta values(3,1);
insert into ta values(1,2);
insert into ta values(4,3);
insert into ta values(2,4);

CREATE OR REPLACE FUNCTION testcur( OUT a integer, OUT b integer )
RETURNS SETOF RECORD AS $$
DECLAREcur refcursor;
BEGINOPEN cur FOR SELECT * FROM ta ORDER BY a DESC;LOOP    FETCH cur INTO a,b;    IF not found THEN        exit;
ELSE       RETURN NEXT;    END IF;END LOOP;CLOSE cur;
 
END;
$$ LANGUAGE 'PLPGSQL' ;

SELECT * FROM testcur();

----------------

As the result I get:

3    1
1    2
4    3
2    4


Which is not ordered by column a!?

Is this intended?
Am I doing something wrong?

I'm using Postgresql 8.3.1

Patrick



pgsql-sql by date:

Previous
From: Patrick Scharrenberg
Date:
Subject: Re: using calculated column in where-clause
Next
From: "Pavel Stehule"
Date:
Subject: Re: order by when using cursors