Re: BUG #17671: Query returns unexpected result

From: Japin Li <japinli(at)hotmail(dot)com>
To: niko(at)aku(dot)mx, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #17671: Query returns unexpected result
Date: 2022-10-31 10:40:56
Message-ID: MEYP282MB1669181D7B00D8ECC198F27CB6379@MEYP282MB1669.AUSP282.PROD.OUTLOOK.COM
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs


On Mon, 31 Oct 2022 at 13:15, PG Bug reporting form <noreply(at)postgresql(dot)org> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 17671
> Logged by: Nikola Mirkov
> Email address: niko(at)aku(dot)mx
> PostgreSQL version: 12.12
> Operating system: Ubuntu 12.12-0ubuntu0.20.
> Description:
>
> Hey guys,
> When I run the following query:
> SELECT foo, bar
> FROM table1
> WHERE fk_id = 637
> AND utc > '2022-10-16'
> UNION
> SELECT foo, bar
> FROM table2
> WHERE fk_id = 637
> AND utc > '2022-10-16'
>
> I'm getting only one row per table. If I add the column "utc" to the list in
> SELECT, I get the expected result.
>
> Why is this happening?
>

The UNION eliminates duplicate rows from its result, in the same way as
DISTINCT [1].

[1] https://www.postgresql.org/docs/current/queries-union.html

--
Regrads,
Japin Li.
ChengDu WenWu Information Technology Co.,Ltd.

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Christoph Berg 2022-10-31 12:18:51 Re: BUG #17672: Wrong logic of Postgresql Resporitory Naming and mirroring incompatibility
Previous Message Kieran McCusker 2022-10-31 10:07:02 Re: BUG #17671: Query returns unexpected result