Thread: Re: ORDER BY elements in ARRAY

Re: ORDER BY elements in ARRAY

From
"David G. Johnston"
Date:
On Tuesday, August 27, 2024, Andreas Joseph Krogh <andreas@visena.com> wrote:

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

Add order by here 

       ) as person_array

FROM onp_crm_relation comp
ORDER BY person_array
;
 
David J.
 

Re: ORDER BY elements in ARRAY

From
"David G. Johnston"
Date:
On Tuesday, August 27, 2024, Andreas Joseph Krogh <andreas@visena.com> wrote:
På tirsdag 27. august 2024 kl. 14:39:34, skrev David G. Johnston <david.g.johnston@gmail.com>:

[…]

Add order by here 
       ) as person_array

FROM onp_crm_relation comp
ORDER BY person_array
;
 
David J.

 

This doesn't really do it. I'm looking for something analogous to Java's Comparator-interface so the custom datatype knows how to sort itself.


Ah.  Then either just put those two values into the first two field positions of your custom type and live with an easy, but also self-contained, hack, or figure out what incantations of create operator and/or create operator family are need to install custom behavior for the b-tree < and > operators.  I’m 80% sure it’s doable, 60% in plpgsql…

David J.