Received: from moutvdom01.kundenserver.de (moutvdom01.kundenserver.de [195.20.224.200]) by postgresql.org (Postfix) with ESMTP id AB10D47598A for ; Wed, 3 Apr 2002 14:15:15 -0500 (EST) Received: from [172.19.20.63] (helo=mrvdomng2.kundenserver.de) by moutvdom01.kundenserver.de with esmtp (Exim 2.12 #2) id 16sqDu-0002VC-00; Wed, 3 Apr 2002 21:15:10 +0200 Received: from [213.7.180.24] (helo=BURNT.asa.de) by mrvdomng2.kundenserver.de with esmtp (Exim 3.22 #2) id 16sqDt-0004d6-00; Wed, 03 Apr 2002 21:15:09 +0200 Message-Id: <5.1.0.14.2.20020403211109.01cf5e40@pop.kundenserver.de> X-Sender: m6261949-7@pop.kundenserver.de X-Mailer: QUALCOMM Windows Eudora Version 5.1 Date: Wed, 03 Apr 2002 21:15:44 +0200 To: pgsql-sql@postgresql.org From: Bernd von den Brincken Subject: Named column in a Function fails at ORDER BY (PgSQL 7.1) Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200204/39 X-Sequence-Number: 7304 Hello, on the occasion of a subselect I found a behavior in PostgreSQL 7.1 that I consider faulty, but would like to hear comments before complaining to the hackers: It seems that pgsql can not use a named result column in a function for ORDER BY. The same named result column can be used in an ORDER BY clause a) directly, _without_ the function or b) _with_ the same function but with the _original_ column name. Here is the example - this fails with "ERROR: Attribute 'max_date' not found": SELECT content, datetime AS max_date FROM cftext ORDER by date_part('hour', max_date) Whereas this works both: a) SELECT content, datetime AS max_date FROM cftext ORDER by max_date b) SELECT content, datetime AS max_date FROM cftext ORDER by date_part('hour', datetime) Now in this example the alternative works fine, but if you use a Sub-SELECT there is no alternative to a named result column. I posted the simple example here to focus on the issue. - Thanks for any hints - // Bernd vdB