From: Andreas Joseph Krogh <andreas@visena.com>
To: pgsql-general@lists.postgresql.org
Subject: Sv: Re: Re: Is ORDER BY in sub-query preserved when outer query is only projection?
Date: Mon, 15 Jan 2018 19:10:22 +0100 (CET)
Message-ID: <VisenaEmail.43.6209c12fcb4ca8ed.160fb03c2da@tc7-visena> (raw)
In-Reply-To: <CAKFQuwbmGjSvP=Kv1Yz_gNUOemHag_JQoS8tuaYrztqwuG_DEQ@mail.gmail.com>
På mandag 15. januar 2018 kl. 19:04:51, skrev David G. Johnston <
david.g.johnston@gmail.com <mailto:david.g.johnston@gmail.com>>:
On Sun, Jan 14, 2018 at 5:40 AM, Andreas Joseph Krogh <andreas@visena.com
<mailto:andreas@visena.com>> wrote:
På søndag 14. januar 2018 kl. 13:30:29, skrev Francisco Olarte <
folarte@peoplecall.com <mailto:folarte@peoplecall.com>>:
Andreas:
On Sun, Jan 14, 2018 at 1:03 PM, Andreas Joseph Krogh
<andreas@visena.com <mailto:andreas@visena.com>> wrote:
> SELECT q.* FROM (
> SELECT comp.id <http://comp.id>, comp.name <http://comp.name;
> FROM company comp JOIN req r ON r.company_id = comp.id <http://comp.id;
> ORDER BY LOWER(comp.name <http://comp.name;) ASC
> ) AS q
> ORDER BY r.status ASC
Do you see any solution sorting on a composite type without using an outer
query?
Tacking on ORDER BY to an inner query is generally not the right thing to do.
What can you not write:
SELECT q.* FROM () AS q
ORDER BY lower(q.name <http://q.name>) ASC, q.status ASC
?
This is what I ended up doing.
Also, ORDER BY r.status ASC in you original query shouldn't work - r is not
visible at that point, only q is.
Yea, this was a thinko from my part, I meant q.status.
-- 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;
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.43.6209c12fcb4ca8ed.160fb03c2da@tc7-visena>
References: <CAKFQuwbmGjSvP=Kv1Yz_gNUOemHag_JQoS8tuaYrztqwuG_DEQ@mail.gmail.com> <VisenaEmail.43.6209c12fcb4ca8ed.160fb03c2da@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