pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-general@lists.postgresql.org
Subject: Is ORDER BY in sub-query preserved when outer query is only projection?
Date: Sun, 14 Jan 2018 13:03:08 +0100 (CET)
Message-ID: <VisenaEmail.19.f8d19b1c4787a72b.160f4879231@tc7-visena> (raw)

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@visena.com <mailto:andreas@visena.com>
www.visena.com <https://www.visena.com;
 <https://www.visena.com;

view thread (4+ messages)  latest in thread

Message-ID: <VisenaEmail.19.f8d19b1c4787a72b.160f4879231@tc7-visena>
Permalink:  ../VisenaEmail.19.f8d19b1c4787a72b.160f4879231@tc7-visena/
Also on:    postgresql.org/message-id/VisenaEmail.19.f8d19b1c4787a72b.160f4879231@tc7-visena

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: andreas@visena.com
  Subject: Re: Is ORDER BY in sub-query preserved when outer query is only projection?
  In-Reply-To: <VisenaEmail.19.f8d19b1c4787a72b.160f4879231@tc7-visena>
  References: <VisenaEmail.19.f8d19b1c4787a72b.160f4879231@tc7-visena>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox