ORDER BY custom type

From: Andreas Joseph Krogh <andreas(at)visena(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: ORDER BY custom type
Date: 2018-01-11 11:00:55
Message-ID: VisenaEmail.167.abde9aaf9b1c0c53.160e4d866b9@tc7-visena
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi all.
 
I have this custom-type:
 
CREATE TYPE PERSONTYPE AS ( id BIGINT, firstname VARCHAR, lastname VARCHAR,
initialsVARCHAR );
 
I'm returning a column with this type using the following query, which lists
activities and its responsible-person (using the PERSONTYPE):
SELECT act.entity_id AS project_id, act.name AS project , (SELECT ROW
(p.entity_id, p.firstname, p.lastname, p.initials)::persontypeFROM
onp_crm_person pWHERE act.responsible = p.onp_user_id) AS responsible_person
fromonp_crm_activity act ORDER BY responsible_person ASC ;
 
But I need to ORDER BY different properties of PERSONTYPE, ie. initials, and
am wondering if there exists a mechanism to achieve the following:
SELECT act.entity_id AS project_id, act.name AS project , (SELECT ROW
(p.entity_id, p.firstname, p.lastname, p.initials)::persontypeFROM
onp_crm_person pWHERE act.responsible = p.onp_user_id) AS responsible_person
fromonp_crm_activity act ORDER BY responsible_person.initials ASC ;
How do I do that?
 
Thanks.
 
-- Andreas Joseph Krogh
CTO / Partner - Visena AS
Mobile: +47 909 56 963
andreas(at)visena(dot)com <mailto:andreas(at)visena(dot)com>
www.visena.com <https://www.visena.com>
<https://www.visena.com>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Durumdara 2018-01-11 12:23:47 Re: String comparison problem in select - too many results
Previous Message Francisco Olarte 2018-01-11 10:11:57 Re: String comparison problem in select - too many results