Re: Order by lower(column-alias) doesn't work...

From: Geoff Winkless <pgsqladmin(at)geoff(dot)dj>
To: Andreas Joseph Krogh <andreas(at)visena(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Order by lower(column-alias) doesn't work...
Date: 2020-05-28 12:50:54
Message-ID: CAEzk6fc_W3o9x18ZXF_G1rwpLWN6deP==XA2EUQQtFt-nPFjEg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, 28 May 2020 at 13:14, Andreas Joseph Krogh <andreas(at)visena(dot)com> wrote:
> This works:
> select p.firstname, p.lastname, p.firstname || p.lastname as fullname from onp_crm_person p order by fullname;
>
> But this doesn't:
> select p.firstname, p.lastname, p.firstname || p.lastname as fullname from onp_crm_person p order by lower(fullname);
> ERROR: column "fullname" does not exist
> LINE 1: ... as fullname from onp_crm_person p order by lower(fullname);

Wrap the original query in either a CTE or a temporary table.
eg

=> SELECT REPLACE(name, '_', ' ') AS nm FROM subs ORDER BY lower(nm);
ERROR: column "nm" does not exist
=> SELECT * FROM (SELECT REPLACE(name, '_', ' ') AS nm FROM subs) AS t
ORDER BY lower(nm);
[results]
=> WITH t AS (SELECT REPLACE(name, '_', ' ') AS nm FROM subs) SELECT
* FROM t ORDER BY lower(nm);
[results]

Geoff

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andreas Joseph Krogh 2020-05-28 12:55:55 Re: Order by lower(column-alias) doesn't work...
Previous Message Marco Lechner 2020-05-28 12:24:53 AW: Linux Update Experience