Thread: COALESCE in ORDER BY...

COALESCE in ORDER BY...

From
"Terry Yapt"
Date:
Why this doesn't run on postrgreSQL 7.3.1 ?

www=> SELECT 10 AS first ORDER BY first DESC;                            first
-------   10
(1 row)

www=> SELECT 10 AS first ORDER BY COALESCE(first,0) DESC;
ERROR:  Attribute "first" not found

Thanks in advance..



Re: COALESCE in ORDER BY...

From
Andreas Schmitz
Date:
Terry Yapt wrote:

>www=> SELECT 10 AS first ORDER BY COALESCE(first,0) DESC;
>ERROR:  Attribute "first" not found
>
>Thanks in advance..
>  
>
Perhaps, this is a bug, but I have a workarround for you till this is 
clariefied:

SELECT *
FROM (SELECT 10 AS FIRST) AS vtbl
ORDER BY COALESCE(vtbl.first,0) DESC;

(Tested with 7.3.2)

Best regards
-- 
Andreas Schmitz
AS-DataService <http://www.as-dataservice.de>
Kastanienallee 24
D-54662 Speicher

Tel.: (0 65 62) 93 05 17
Fax: (0 65 62) 93 05 18
Email: andreas.schmitz@as-dataservice.de 
<mailto:andreas.schmitz@as-dataservice.de>

Ust-IdNr.: DE211466407
Handelsregister: HRA 1869 - Amtsgericht Bitburg
<http://www.as-dataservice.de>




Re: COALESCE in ORDER BY...

From
Stephan Szabo
Date:
On Sat, 17 May 2003, Andreas Schmitz wrote:

> Terry Yapt wrote:
>
> >www=> SELECT 10 AS first ORDER BY COALESCE(first,0) DESC;
> >ERROR:  Attribute "first" not found
> >
> >Thanks in advance..
> >
> >
> Perhaps, this is a bug, but I have a workarround for you till this is
> clariefied:

Just an unimplemented enhancement I think.  At least in SQL92, order
by expressions need to be column references (possibly with collation
conversions), we allow some functional order by expressions, but not one's
referencing select aliases I think.



Re: COALESCE in ORDER BY...

From
"Terry Yapt"
Date:
Ok Thanks Andreas, but It was only curiosity because in Oracle I usually use this kind of ORDER BY on SQL's.

Thanks...

-----Original Message-----
From: Andreas Schmitz <andreas.schmitz@as-dataservice.de>
To: Terry Yapt <pgsql@technovell.com>
Date: Sat, 17 May 2003 19:14:09 +0200
Subject: Re: [SQL] COALESCE in ORDER BY...

Terry Yapt wrote:

>www=> SELECT 10 AS first ORDER BY COALESCE(first,0) DESC;
>ERROR:  Attribute "first" not found
>
>Thanks in advance..
>
>
Perhaps, this is a bug, but I have a workarround for you till this is
clariefied:

SELECT *
FROM (SELECT 10 AS FIRST) AS vtbl
ORDER BY COALESCE(vtbl.first,0) DESC;

(Tested with 7.3.2)

Best regards
--
Andreas Schmitz
AS-DataService <http://www.as-dataservice.de>
Kastanienallee 24
D-54662 Speicher

Tel.: (0 65 62) 93 05 17
Fax: (0 65 62) 93 05 18
Email: andreas.schmitz@as-dataservice.de
<mailto:andreas.schmitz@as-dataservice.de>

Ust-IdNr.: DE211466407
Handelsregister: HRA 1869 - Amtsgericht Bitburg
<http://www.as-dataservice.de>