ORDER BY elements in ARRAY

Andreas Joseph Krogh <andreas@visena.com>

From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-sql@lists.postgresql.org
Date: 2024-08-27T11:22:49Z
Lists: pgsql-sql

Hi, I have this query:


SELECT comp.entity_id as company_id, comp.companyname AS company_name , ARRAY( 
SELECT (pers.entity_id , pers.firstname , pers.lastname )::PersonTypeTest FROM 
onp_crm_person AS pers WHERE pers.relation_id = comp.entity_id ) as 
person_array FROM onp_crm_relation comp ORDER BY person_array ;


And I'd like to ORDER BY (conceptually) lower(pers.firstname), 
lower(pers.lastname). I realize there might be more than 1 person in the array, 
so I'd like to order by “firstname and lastname of first element, the same for 
second etc.”



Any way to do this?






--
Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas@visena.com <mailto:andreas@visena.com>
www.visena.com <https://www.visena.com>
 <https://www.visena.com>