Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 524E116AF4E5 for ; Mon, 30 Jul 2012 13:21:58 -0300 (ADT) Received: from nm30.bullet.mail.bf1.yahoo.com ([98.139.212.189]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1SvsjC-0003xb-Sh for pgsql-bugs@postgresql.org; Mon, 30 Jul 2012 16:21:57 +0000 Received: from [98.139.212.148] by nm30.bullet.mail.bf1.yahoo.com with NNFMP; 30 Jul 2012 16:21:40 -0000 Received: from [98.139.211.201] by tm5.bullet.mail.bf1.yahoo.com with NNFMP; 30 Jul 2012 16:21:40 -0000 Received: from [127.0.0.1] by smtp210.mail.bf1.yahoo.com with NNFMP; 30 Jul 2012 16:21:40 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1343665300; bh=XWRhFz3cSMJCmDdTxiF0DEDgrZJ8Z/N+C9URVqA/a10=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:Message-ID:Date:From:User-Agent:MIME-Version:To:CC:Subject:References:In-Reply-To:Content-Type:Content-Transfer-Encoding; b=qGixBl2mlZHXfLnvokv1nscAMPe0LMzpXNMjmuibdHye5+E3iD4h+bOl2SSvuILxCYvmvBZKSg3K3nvc1Oy0o8Ajzq6ILsQ5v4nFqfV79CM9QcB7xYY9ySHmP6CKw7srgg9o+2vBS/5xJFGNwmXFXKhgnJ6qocGRPBdEjbLd1Zc= X-Yahoo-Newman-Id: 837074.78292.bm@smtp210.mail.bf1.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: eZGM1eQVM1lbLlPEl1fZm9BCImA8RewHjmD9jFM457rxB2g Ifjc8pNxS4gxNJfJ9cMwJ6hkiMlOEu043oScaYXbVzvBY1qVZeDNGWSV_4hI 31_vClEBerXX03yVOAstcwbSfIFNExmu35tCAUMuOC5_O2nky.S6OR17M42H KrhN5lX_RpS0yz4JC06m7DMzToECfzIDTIhqE5a5kijURPh.2HD2LVo89MSj Xldv2siF.dXLr20CWx4TVnb9ViJL9KGr48IkO9TVpfynhICrv.xlUtzT3h0f QGj4AC_HTs_wuQf6XAIX7_nVe9lus0BowX.H.p2j7pp_D8RErhSAHmw8wPAm G9vh_jDfpHG9tcsznlBvdYTirEc9qTjeRfrjWwbBkA2T0xwgQ18XH3HZXY5Y EjnZNiNBkRz3XAPs8le2LluHO6EU05nFwO8E2vbrPNWFcE54193JXSfK_IWW Mvo8urZL8 X-Yahoo-SMTP: auMih2KswBAUyVy7YHrIeglmGa00 Received: from [172.21.8.137] (JanWieck@173.49.130.61 with plain) by smtp210.mail.bf1.yahoo.com with SMTP; 30 Jul 2012 09:21:40 -0700 PDT Message-ID: <5016B492.5030807@Yahoo.com> Date: Mon, 30 Jul 2012 12:21:38 -0400 From: Jan Wieck User-Agent: Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20120713 Thunderbird/14.0 MIME-Version: 1.0 To: Boris Folgmann CC: pgsql-bugs@postgresql.org Subject: Re: BUG #6774: FOR IN SELECT LOOP ignores ORDER BY References: <20120727160324.GA11439@depesz.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201207/234 X-Sequence-Number: 33710 On 7/30/2012 5:56 AM, Boris Folgmann wrote: > Hi, > > hubert depesz lubaczewski schrieb/wrote: >> generally - order by datname is understood as "order by *variable >> datname*". - which is null. > > It's clear that it's a shadowing problem. But it's not a "FOR IN EXECUTE" > where a variable makes sense. I mean why is a "ORDER BY variable" valid in > "FOR IN"? In SQL you can't use ORDER BY NULL. If the order by clause is not > correct the whole statement should raise an error. Note that PL/pgSQL replaces all local variables inside a query with $-parameters for the prepared SPI plan. The parser rejects ordering by non-integer constants, but it does not reject ordering by $-parameters or constant expressions. (maybe it should). You can for example SELECT * FROM something ORDER BY 'foo'||'bar'; Jan -- Anyone who trades liberty for security deserves neither liberty nor security. -- Benjamin Franklin