Named column in a Function fails at ORDER BY (PgSQL 7.1)

From: Bernd von den Brincken <bvdb(at)asa(dot)de>
To: pgsql-sql(at)postgresql(dot)org
Subject: Named column in a Function fails at ORDER BY (PgSQL 7.1)
Date: 2002-04-03 19:15:44
Message-ID: 5.1.0.14.2.20020403211109.01cf5e40@pop.kundenserver.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Samuel J. Sutjiono 2002-04-03 19:25:50 Re: [SQL] Logging option
Previous Message Bruce Momjian 2002-04-03 19:07:41 Re: [SQL] Logging option