From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: cute_hoay88@hotmail.com
Subject: BUG #17818: CTE is not returning the right data.
Date: Thu, 02 Mar 2023 08:33:51 +0000
Message-ID: <17818-2ef0f7567df79f09@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 17818
Logged by: Shiau Hoay Ong
Email address: cute_hoay88@hotmail.com
PostgreSQL version: 12.1
Operating system: window
Description:
Hi Postgresql Support Team, today i encounter a mystery case. The Stored
Procedure is already used for sometime, but today there are some issue in
this Stored Procedure which causing the data got deleted. The scenario is
like sample below :
WITH cte_primary_data AS
(
SELECT mr.id, f.feature, mr.item, mr.data_type_id
FROM public.primary_tables mr
INNER JOIN public.feature_tables f
ON f.feature_id = mr.feature_id
WHERE mr.id = 3163
AND mr.team_id = 23
AND mr.stage_id = 2
)
SELECT * FROM cte_primary_data l
INNER JOIN temp_flat_data f
ON l.feature = f.feature
AND l.item = f.item
Scenario: When i execute this above query, i am not able to find the feature
AA and Item AA EXT Inner-Lane- 1.1G.
But weird is i tried out with this (below example: Add WHERE inside the
cte), then i am able to get the item:
WITH cte_primary_data AS
(
SELECT mr.id, f.feature, mr.item, mr.data_type_id
FROM public.primary_tables mr
INNER JOIN public.feature_tables f
ON f.feature_id = mr.feature_id
WHERE mr.id = 3163
AND mr.team_id = 23
AND mr.stage_id = 2
AND mr.item = 'AA EXT Inner-Lane- 1.1G'
AND f.feature = 'AA'
)
SELECT * FROM cte_primary_data l
INNER JOIN temp_flat_data f
ON l.feature = f.feature
AND l.item = f.item
I do try out with Create Temp Table also work fine with the sample without
need filtering (as filtering will only reduce data record set).
Can you please help to investigate and explain what is the possible root
cause for this?
Thanks!
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 using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: noreply@postgresql.org, pgsql-bugs@lists.postgresql.org, cute_hoay88@hotmail.com
Subject: Re: BUG #17818: CTE is not returning the right data.
In-Reply-To: <17818-2ef0f7567df79f09@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