pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #17671: Query returns unexpected result
3+ messages / 3 participants
[nested] [flat]
* BUG #17671: Query returns unexpected result
@ 2022-10-31 05:15 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 2 replies; 3+ messages in thread
From: PG Bug reporting form @ 2022-10-31 05:15 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: niko@aku.mx
The following bug has been logged on the website:
Bug reference: 17671
Logged by: Nikola Mirkov
Email address: niko@aku.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?
Thank you so much!
Niko
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #17671: Query returns unexpected result
@ 2022-10-31 10:07 Kieran McCusker <kieran.mccusker@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: Kieran McCusker @ 2022-10-31 10:07 UTC (permalink / raw)
To: niko@aku.mx; pgsql-bugs@lists.postgresql.org
It's not a bug. Union removes duplicates. Use union all.
Kieran
On Mon, 31 Oct 2022, 10:03 PG Bug reporting form, <noreply@postgresql.org>
wrote:
> The following bug has been logged on the website:
>
> Bug reference: 17671
> Logged by: Nikola Mirkov
> Email address: niko@aku.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?
>
> Thank you so much!
> Niko
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #17671: Query returns unexpected result
@ 2022-10-31 10:40 Japin Li <japinli@hotmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: Japin Li @ 2022-10-31 10:40 UTC (permalink / raw)
To: niko@aku.mx; pgsql-bugs@lists.postgresql.org
On Mon, 31 Oct 2022 at 13:15, PG Bug reporting form <noreply@postgresql.org> wrote:
> The following bug has been logged on the website:
>
> Bug reference: 17671
> Logged by: Nikola Mirkov
> Email address: niko@aku.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.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2022-10-31 10:40 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-10-31 05:15 BUG #17671: Query returns unexpected result PG Bug reporting form <noreply@postgresql.org>
2022-10-31 10:07 ` Kieran McCusker <kieran.mccusker@gmail.com>
2022-10-31 10:40 ` Japin Li <japinli@hotmail.com>
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