Is ORDER BY in sub-query preserved when outer query is only projection?

From: Andreas Joseph Krogh <andreas(at)visena(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Is ORDER BY in sub-query preserved when outer query is only projection?
Date: 2018-01-14 12:03:08
Message-ID: VisenaEmail.19.f8d19b1c4787a72b.160f4879231@tc7-visena
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi.
 
I have this query:
 
SELECT q.* FROM (
  SELECT comp.id, comp.name
  FROM company comp JOIN req r ON r.company_id = comp.id
  ORDER BY LOWER(comp.name) ASC
) AS q
ORDER BY r.status ASC
 
What I'm trying to do here is to order by some status (which may be only 1 of
3 values, for instance OPEN, IN_PROGRESS, CLOSED), then order by company-name
so I get results for each status sorted by company-name.
 
Is this kind of sort stable, can I assume the pre-sorted result's order is
preserved so I achieve what I want?
 
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 Francisco Olarte 2018-01-14 12:20:05 Re: String comparison problem in select - too many results
Previous Message Peter J. Holzer 2018-01-14 11:14:07 Re: String comparison problem in select - too many results