Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeI4p-00053z-6N for pgsql-general@arkaria.postgresql.org; Thu, 28 May 2020 12:56:03 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jeI4m-0003yZ-9m for pgsql-general@arkaria.postgresql.org; Thu, 28 May 2020 12:56:00 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jeI4m-0003yS-19 for pgsql-general@lists.postgresql.org; Thu, 28 May 2020 12:56:00 +0000 Received: from post.visena.com ([46.226.10.50]) by makus.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.92) (envelope-from ) id 1jeI4j-0003kg-Qx for pgsql-general@lists.postgresql.org; Thu, 28 May 2020 12:55:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=visena.com; s=20141101.wh; h=Content-Type:MIME-Version:Subject:References:In-Reply-To:Message-ID:Cc:To:From:Date; bh=Sfvkig5VIZb9nqhX9viigRslt/jiCNB2q3zlyuwzpjM=; b=LgBY5QUQWkyv0hGpcDXWpxxx/K024SbctrKgd6Iuvq0e6r57PXnxE4x1C0Kiv+dZnVwqWa6dOLGaThWBPaSY6lEfjXatZx5DCmy+/GmjBvl5bSKjcseusjBIcQeSX1oDQJcr8Otdn78jLXAz86yDJEjLHVFqWrRs+Db2Zm7edzk=; Received: from [10.0.1.10] (helo=tc7-visena.wh.internal.visena.com) by post.visena.com with esmtp (Exim 4.82) (envelope-from ) id 1jeI4h-0008Bu-Hl; Thu, 28 May 2020 14:55:55 +0200 Received: from localhost ([127.0.0.1] helo=tc7-visena.wh.internal.visena.com) by tc7-visena.wh.internal.visena.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jeI4h-0001Ws-Fr; Thu, 28 May 2020 14:55:55 +0200 Date: Thu, 28 May 2020 14:55:55 +0200 (CEST) From: Andreas Joseph Krogh To: Geoff Winkless Cc: "pgsql-generallists.postgresql.org" Message-ID: In-Reply-To: References: Subject: Re: Order by lower(column-alias) doesn't work... MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_225_522211459.1590670555427" X-Mailer: Visena Mail 2.2.306-SNAPSHOT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_225_522211459.1590670555427 Content-Type: multipart/related; boundary="----=_Part_226_56409013.1590670555427" ------=_Part_226_56409013.1590670555427 Content-Type: multipart/alternative; boundary="----=_Part_227_289186948.1590670555437" ------=_Part_227_289186948.1590670555437 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable P=C3=A5 torsdag 28. mai 2020 kl. 14:50:54, skrev Geoff Winkless >:=20 On Thu, 28 May 2020 at 13:14, Andreas Joseph Krogh wro= te: > This works: > select p.firstname, p.lastname, p.firstname || p.lastname as fullname fr= om=20 onp_crm_person p order by fullname; > > But this doesn't: > select p.firstname, p.lastname, p.firstname || p.lastname as fullname fr= om=20 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 [..]=20 Yea, I was hoping to avoid that, as the query is generated and rewriting it= is=20 a pain...=20 Is there a way to define "sorting-rules" on custom-types so that I can have= =20 ORDER BY and PG will pick my custom oderin= g?=20 -- Andreas Joseph Krogh ------=_Part_227_289186948.1590670555437 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
P=C3=A5 torsdag 28. mai 2020 kl. 14:50:54, skrev Geoff Winkless <pgsqladmin@geoff.dj>:
On = Thu, 28 May 2020 at 13:14, Andreas Joseph Krogh <andreas@visena.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:=C2=A0 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
[..]
=C2=A0
Yea, I was hoping to avoid that, as the query is generated and rewriti= ng it is a pain...
=C2=A0
Is there a way to define "sorting-rules" on custom-types so = that I can have ORDER BY <my_array_of_custom_types_alias> and PG will= pick my custom odering?
=C2=A0
">
--
Andreas Joseph Krogh
------=_Part_227_289186948.1590670555437-- ------=_Part_226_56409013.1590670555427-- ------=_Part_225_522211459.1590670555427--