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 

Reply via email to