Re: BUG #6774: FOR IN SELECT LOOP ignores ORDER BY - Mailing list pgsql-bugs

From hubert depesz lubaczewski
Subject Re: BUG #6774: FOR IN SELECT LOOP ignores ORDER BY
Date
Msg-id 20120727160324.GA11439@depesz.com
Whole thread Raw
In response to BUG #6774: FOR IN SELECT LOOP ignores ORDER BY  (boris@folgmann.de)
Responses Re: BUG #6774: FOR IN SELECT LOOP ignores ORDER BY  (Boris Folgmann <boris@folgmann.de>)
List pgsql-bugs
On Fri, Jul 27, 2012 at 02:56:18PM +0000, boris@folgmann.de wrote:
> This is an really interesting one!
> I've trimmed down the problem so you can simply reproduce it by copy &
> paste:
> The only difference of the two functions is that the first one uses a
> variable with the same name of a column.
> This might be a feature and not a bug, but browsing through the
> documentation I could not find any documented restrictions on variable names
> in this context.

and the variable name is the problem.

generally - order by datname is understood as "order by *variable
datname*". - which is null.

change the select to:
select d.* from pg_database d order by d.datname
and now there is no more problem - because you're no longer using
ambiguous identifier.

Also, check this:
http://www.depesz.com/2009/12/16/waiting-for-8-5-plpgsql-variable-resolution/

Best regards,

depesz

--
The best thing about modern society is how easy it is to avoid contact with it.
                                                             http://depesz.com/

pgsql-bugs by date:

Previous
From: boris@folgmann.de
Date:
Subject: BUG #6774: FOR IN SELECT LOOP ignores ORDER BY
Next
From: Simon Riggs
Date:
Subject: Re: primary and hot standby database don' work now