From: Tom Lane <tgl@sss.pgh.pa.us>
To: mtv.spec@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #14733: unexpected query result
Date: Tue, 04 Jul 2017 11:14:59 -0400
Message-ID: <2912.1499181299@sss.pgh.pa.us> (raw)
In-Reply-To: <20170704111914.27954.71162@wrigleys.postgresql.org>
References: <20170704111914.27954.71162@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
mtv.spec@gmail.com writes:
> Table 1 - Customer:
> CREATE TABLE test.e_customer (
> id SERIAL PRIMARY KEY,
> name VARCHAR NOT NULL
> );
> Data:
> INSERT INTO test.e_customer (name)
> VALUES ('John'), ('Jane');
> Table 2 - Order:
> CREATE TABLE test.e_order (
> id SERIAL PRIMARY KEY,
> e_customer_id INTEGER REFERENCES customer (id),
> amount NUMERIC NOT NULL
> );
This example fails right here for me, because there's no table named
"customer". When I change the clause to REFERENCES test.e_customer (id)
then it works, and I get the output you show for "Postgres". It looks
correct to me: given the way you wrote the WHERE clause, the row in
e_order with a null e_customer_id will join with every row in e_customer.
What you show as desired output could be achieved with a left join,
but this isn't one.
=# SELECT
o.id,
c.name,
o.amount
FROM
test.e_order o LEFT JOIN
test.e_customer c
ON o.e_customer_id = c.id
ORDER BY o.id ASC;
id | name | amount
----+------+--------
1 | John | 1000
2 | | 2000
(2 rows)
> Why PostgreSQL and Oracle return different results?
You'd have to take that up with an Oracle person. But I wonder if
you weren't confusing yourself with tables of slightly different
names, so that you weren't actually testing the same case in both
DBMSes. Or maybe you were using Oracle's nonstandard left join syntax
and mistranslating that to Postgres.
regards, tom lane
--
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: tgl@sss.pgh.pa.us, mtv.spec@gmail.com
Subject: Re: BUG #14733: unexpected query result
In-Reply-To: <2912.1499181299@sss.pgh.pa.us>
References: <20170704111914.27954.71162@wrigleys.postgresql.org> <2912.1499181299@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