From: ozzi_99@hotmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #14316: union all with order by "missing from-clause"
Date: Thu, 08 Sep 2016 09:45:56 +0000
Message-ID: <20160908094556.1403.54409@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
The following bug has been logged on the website:
Bug reference: 14316
Logged by: Ossi Kasurinen
Email address: ozzi_99@hotmail.com
PostgreSQL version: 9.5.4
Operating system: windows 8.1 pro
Description:
/*I cannot do "union all" operation with "order by" to another table than
the primary.
example tables and select clause:*/
--table creation: bar
CREATE TABLE public.bar
(
id integer NOT NULL,
sortcolumn integer,
CONSTRAINT pk_bar PRIMARY KEY (id)
)
--table creation:foo
CREATE TABLE public.foo
(
id integer NOT NULL,
barid integer,
sortcolumn integer,
CONSTRAINT pk_foo PRIMARY KEY (id),
CONSTRAINT fk_second FOREIGN KEY (barid)
REFERENCES public.bar (id) MATCH SIMPLE
ON UPDATE CASCADE ON DELETE CASCADE
)
-- insert some dummy data.
-- the following doesn't work
select origin.id, origin.barid, origin.sortcolumn from foo origin
inner join bar on origin.barId = bar.Id
union all
select a.id, a.barid, a.sortcolumn from foo as a
inner join bar as b on a.barid = b.id
order by b.sortcolumn
limit 1
/* If I take "b" away from order by, it will order by table foo, and it
gives incorrect results. */
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
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-bugs@postgresql.org
Cc: ozzi_99@hotmail.com
Subject: Re: BUG #14316: union all with order by "missing from-clause"
In-Reply-To: <20160908094556.1403.54409@wrigleys.postgresql.org>
References: <20160908094556.1403.54409@wrigleys.postgresql.org>
* 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