Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 30347152A2F6 for ; Fri, 27 Jul 2012 13:03:41 -0300 (ADT) Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Sun0t-0002hv-4J for pgsql-bugs@postgresql.org; Fri, 27 Jul 2012 16:03:41 +0000 Received: from andy.depesz.com ([88.198.47.100] helo=depesz.com) by depesz.com with esmtpa (Exim 4.80) (envelope-from ) id 1Sun0e-0003h7-P2; Fri, 27 Jul 2012 18:03:24 +0200 Date: Fri, 27 Jul 2012 18:03:24 +0200 From: hubert depesz lubaczewski To: boris@folgmann.de Cc: pgsql-bugs@postgresql.org Subject: Re: BUG #6774: FOR IN SELECT LOOP ignores ORDER BY Message-ID: <20120727160324.GA11439@depesz.com> Reply-To: depesz@depesz.com References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.21 (2010-09-15) X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201207/225 X-Sequence-Number: 33701 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/