pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ruslan Zakirov <ruslan.zakirov@gmail.com>
Cc: Thomas Kellerer <shammat@gmx.net>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Reproducing incorrect order with order by in a subquery
Date: Tue, 13 Jun 2023 11:06:53 -0400
Message-ID: <1635592.1686668813@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMOxC8tvSx1Dduu5CvBTZ3eZdNMyE9=S2PSiypWKafVaF=-9nQ@mail.gmail.com>
References: <CAMOxC8tBBR8DK3c73zUWSWRzTPP2FHv5+sLFqL2ZWWwLqGmzhw@mail.gmail.com>
	<dd2f192c-2b90-2bb7-27b4-004af7e7e26a@gmx.net>
	<CAMOxC8tvSx1Dduu5CvBTZ3eZdNMyE9=S2PSiypWKafVaF=-9nQ@mail.gmail.com>

Ruslan Zakirov <ruslan.zakirov@gmail.com> writes:
> I know how to fix the problem and I know that ORDER BY should be in the
> outermost select.

> However, I want to write a test case that shows that the old code is wrong,
> but can not create
> minimal set of tables to reproduce it. With this I'm looking for help.

The ORDER BY in the sub-select will be honored at the output of the
sub-select.  To have a different ordering at the final output, you
need the upper query to do something that would re-order the rows.
Joining the sub-select to something else might make that happen,
or you could apply DISTINCT or some other non-trivial processing
in the upper query.

			regards, tom lane





view thread (11+ messages)  latest in thread

Message-ID: <1635592.1686668813@sss.pgh.pa.us>
Permalink:  ../1635592.1686668813@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1635592.1686668813@sss.pgh.pa.us

 · 

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: tgl@sss.pgh.pa.us, ruslan.zakirov@gmail.com, shammat@gmx.net
  Subject: Re: Reproducing incorrect order with order by in a subquery
  In-Reply-To: <1635592.1686668813@sss.pgh.pa.us>
  References: <CAMOxC8tBBR8DK3c73zUWSWRzTPP2FHv5+sLFqL2ZWWwLqGmzhw@mail.gmail.com> <dd2f192c-2b90-2bb7-27b4-004af7e7e26a@gmx.net> <CAMOxC8tvSx1Dduu5CvBTZ3eZdNMyE9=S2PSiypWKafVaF=-9nQ@mail.gmail.com> <1635592.1686668813@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