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 1jeHQu-0003Sw-Ex for pgsql-general@arkaria.postgresql.org; Thu, 28 May 2020 12:14:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jeHQt-0007A0-2h for pgsql-general@arkaria.postgresql.org; Thu, 28 May 2020 12:14:47 +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 1jeHQs-00076v-FY for pgsql-general@lists.postgresql.org; Thu, 28 May 2020 12:14:46 +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 1jeHQq-0003L1-2B for pgsql-general@lists.postgresql.org; Thu, 28 May 2020 12:14:45 +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:Message-ID:To:From:Date; bh=osHdGRQTxcxpzPyNAE1FB/P+fWrH+4EWeG5ADlrwS3c=; b=snDRXRzmf1hUCnVzkMROmFTAUmV0B4QIQP1Fcadrfnv/qu5IUfUCrCshhhr6xLoSfPtFvyUwArmyWbAkCrXmom+FJwTgVNFsd8T9PeVfFrwh81nTGD2JQ3qcRFmInVmYER5bN+7BbUvnRFPKF+b3FGSL4Nqdr6f0avlFC0kZ9Hw=; 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 1jeHQn-0006oR-Rs for pgsql-general@lists.postgresql.org; Thu, 28 May 2020 14:14:41 +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 1jeHQn-0007p5-Q4 for pgsql-general@lists.postgresql.org; Thu, 28 May 2020 14:14:41 +0200 Date: Thu, 28 May 2020 14:14:41 +0200 (CEST) From: Andreas Joseph Krogh To: pgsql-general@lists.postgresql.org Message-ID: Subject: Order by lower(column-alias) doesn't work... MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_200_1295204179.1590668081745" X-Mailer: Visena Mail 2.2.306-SNAPSHOT List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------=_Part_200_1295204179.1590668081745 Content-Type: multipart/related; boundary="----=_Part_201_1206332796.1590668081751" ------=_Part_201_1206332796.1590668081751 Content-Type: multipart/alternative; boundary="----=_Part_202_2052230871.1590668081767" ------=_Part_202_2052230871.1590668081767 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Hi. 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); This is just an example-query, in my real query I have a more complex query generating an array of a custom-type which is then referenced to as a column-alias, and then ORDER BY on a function tranforming this array doesn't work: SELECT ... ARRAY(WITH RECURSIVE t AS (SELECT ... ) SELECT ROW(t.entity_id, t.name)::BigIntVarChar from t order by level DESC) as folder_parent_array ORDER BY bigintvarchar_to_text_value_flatten(folder_parent_array) ASC; column "folder_parent_array" does not exist What bigintvarchar_to_text_value_flatten() does is to take the "varchar"-part out of the BigintVarchar-type and "flatten" the array by that value so that it sorts nicely. Any way round this? -- Andreas Joseph Krogh ------=_Part_202_2052230871.1590668081767 Content-Type: text/html;charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Hi.
=C2=A0
This works:
select p.firstname, p.lastname, p.firstname || p.lastname as fullname = from onp_crm_person p order by fullname;
=C2=A0
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=A0column "fullname" does not exist
LINE 1: ... as fullname from onp_crm_person p order by lower(fullname);
=C2=A0
This is just an example-query,=C2=A0in my real query I have a more com= plex query generating an array of a custom-type which is then referenced to= as a column-alias, and then ORDER BY on a function tranforming this array = doesn't work:
=C2=A0
SELECT ...
ARRAY(WITH RECURSIVE t AS (SELECT
...
= )=C2=A0SELECT ROW(t.entity_id, t.name)::BigIntVarChar from t order b= y level DESC) as folder_parent_array
=C2=A0
=C2=A0
ORDER BY =C2=A0bigintvarchar_to_text_value_flatten(folder_parent_array= ) ASC;
column "folder_parent_array" does not exist
=C2=A0
What=C2=A0bigintvarchar_to_text_value_flatten() does is to take the &q= uot;varchar"-part out of the BigintVarchar-type and "flatten"= ; the array by that value so that it sorts nicely.

Any way round this?
=C2=A0
">
--
Andreas Joseph Krogh
------=_Part_202_2052230871.1590668081767-- ------=_Part_201_1206332796.1590668081751-- ------=_Part_200_1295204179.1590668081745--