Re: Order by behaviour - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: Order by behaviour
Date
Msg-id 460AE678.2090300@iol.ie
Whole thread Raw
In response to Order by behaviour  ("Carlos H. Reimer" <carlos.reimer@opendb.com.br>)
List pgsql-general
On 28/03/2007 22:52, Carlos H. Reimer wrote:

> SELECT substr(nomerazao,1,4),
> ascii(substr(nomerazao,1,1)),
> ascii(substr(nomerazao,2,1))
> from spunico.unico order by nomerazao;

You need to add aliases to the returned column by which you'd like to
order the result: your query is ordering the rows according to the
column "nomerazao" in the original table, rather than by the substr()
value returned.

Do something like this:

    SELECT substr(nomerazao,1,4) AS my_col,
    ascii(substr(nomerazao,1,1)),
    ascii(substr(nomerazao,2,1))
    from spunico.unico order by my_col;

HTH

Ray.

---------------------------------------------------------------
Raymond O'Donnell, Director of Music, Galway Cathedral, Ireland
rod@iol.ie
---------------------------------------------------------------

pgsql-general by date:

Previous
From: "Carlos H. Reimer"
Date:
Subject: Order by behaviour
Next
From: Peter Eisentraut
Date:
Subject: Re: Order by behaviour