From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Gauthier <davegauthierpg@gmail.com>
Cc: Postgres General <pgsql-general@postgresql.org>
Subject: Re: order by not working in view ?
Date: Thu, 09 Apr 2020 10:41:37 -0400
Message-ID: <5555.1586443297@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMBRECCk-JuysUnYTnNZwS__rOYbicQ3_6yqXRKKPO22doCOqQ@mail.gmail.com>
References: <CAMBRECCk-JuysUnYTnNZwS__rOYbicQ3_6yqXRKKPO22doCOqQ@mail.gmail.com>
David Gauthier <davegauthierpg@gmail.com> writes:
> In the copy/paste below, first 2 lines returned by a select on the view,
> why didn't it sort on start_datetime correctly ?
Putting an ORDER BY in a view is a bit dangerous (last I looked,
it wasn't even legal in standard SQL). Yeah, the view will sort,
but there is nothing compelling the calling query to preserve
the ordering.
EXPLAIN would give you more info, but I'm betting that the IN is being
converted to a semijoin and then done with a non-order-preserving join
method.
regards, tom lane
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: tgl@sss.pgh.pa.us, davegauthierpg@gmail.com
Subject: Re: order by not working in view ?
In-Reply-To: <5555.1586443297@sss.pgh.pa.us>
References: <CAMBRECCk-JuysUnYTnNZwS__rOYbicQ3_6yqXRKKPO22doCOqQ@mail.gmail.com> <5555.1586443297@sss.pgh.pa.us>
* 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