pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter Eisentraut <peter_e@gmx.net>
To: Matthias Kurz <m.kurz@irregular.at>
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #6146: COLLATE in ORDER BY not working with column names defined with "AS"
Date: Sat, 06 Aug 2011 11:53:45 +0300
Message-ID: <1312620825.24721.8.camel@vanquo.pezone.net> (raw)
In-Reply-To: <201108032102.p73L2gT0082970@wwwmaster.postgresql.org>
References: <201108032102.p73L2gT0082970@wwwmaster.postgresql.org>

On ons, 2011-08-03 at 21:02 +0000, Matthias Kurz wrote:
> SELECT 
> 	a.companyname AS a_companyname,
> 	a.street,
> 	a.zip,
> 	a.city,
> 	a.country
> FROM
> 	myAddress a
> ORDER BY
>  	a_companyName COLLATE "C" DESC,
> 	a.street COLLATE "C" ASC,
> 	a.zip COLLATE "C" ASC,
> 	a.city COLLATE "C" ASC,
> 	a.country COLLATE "C" ASC
> ---
> 
> Gives me following error:
> ---
> ERROR:  column "a_companyname" does not exist
> LINE 26:   a_companyName COLLATE "C" ASC,
> ---

ORDER BY can only refer to output columns by themselves, not as part of
an expression.  This is the same issue that

SELECT a AS x FROM foo ORDER BY x

works but

SELECT a AS x FROM foo ORDER BY x + 1

doesn't.

What is perhaps not obvious is that (a_companyName COLLATE "C") is an
expression.  The COLLATE clause is not specifically part of the ORDER BY
syntax, but a general expression.

> Is this the right behaviour?
> Or a bug?

Well, it works as designed and documented, and it is consistent with
other behaviors, as I showed.  The SQL standard is sufficiently murky on
this subject, however, that I can't tell right now whether this is how
it is supposed to work.  But it looks like someone researched this
carefully in the past, so probably yes.





view thread (2+ messages)

Message-ID: <1312620825.24721.8.camel@vanquo.pezone.net>
Permalink:  ../1312620825.24721.8.camel@vanquo.pezone.net/
Also on:    postgresql.org/message-id/1312620825.24721.8.camel@vanquo.pezone.net

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: peter_e@gmx.net, m.kurz@irregular.at
  Subject: Re: BUG #6146: COLLATE in ORDER BY not working with column names defined with "AS"
  In-Reply-To: <1312620825.24721.8.camel@vanquo.pezone.net>
  References: <201108032102.p73L2gT0082970@wwwmaster.postgresql.org> <1312620825.24721.8.camel@vanquo.pezone.net>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox