Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Data Bases > Pgsql Sql > order by when u...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 3534 of 3799
Post > Topic >>

order by when using cursors

by pittipatti@[EMAIL PROTECTED] (Patrick Scharrenberg) Jun 18, 2008 at 08:02 AM

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 $$
DECLARE
	cur refcursor;
BEGIN
	OPEN 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


-- 
Sent via pgsql-sql mailing list (pgsql-sql@[EMAIL PROTECTED]
)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql
 




 4 Posts in Topic:
order by when using cursors
pittipatti@[EMAIL PROTECT  2008-06-18 08:02:43 
Re: order by when using cursors
pavel.stehule@[EMAIL PROT  2008-06-18 08:44:08 
Re: order by when using cursors
pavel.stehule@[EMAIL PROT  2008-06-18 08:54:31 
Re: order by when using cursors
pittipatti@[EMAIL PROTECT  2008-06-18 09:41:53 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Dec 2 21:46:04 CST 2008.