pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-general@lists.postgresql.org
Subject: Order by lower(column-alias) doesn't work...
Date: Thu, 28 May 2020 14:14:41 +0200 (CEST)
Message-ID: <VisenaEmail.2b.86f8bc58bbd29c56.1725b2fd4cc@tc7-visena> (raw)


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 

view thread (5+ messages)  latest in thread

Message-ID: <VisenaEmail.2b.86f8bc58bbd29c56.1725b2fd4cc@tc7-visena>
Permalink:  ../VisenaEmail.2b.86f8bc58bbd29c56.1725b2fd4cc@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.2b.86f8bc58bbd29c56.1725b2fd4cc@tc7-visena

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andreas@visena.com
  Subject: Re: Order by lower(column-alias) doesn't work...
  In-Reply-To: <VisenaEmail.2b.86f8bc58bbd29c56.1725b2fd4cc@tc7-visena>
  References: <VisenaEmail.2b.86f8bc58bbd29c56.1725b2fd4cc@tc7-visena>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox