pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 798604270@qq.com
Subject: BUG #19036: Failed prepared INSERT statement make another SELECT query generate wrong result
Date: Fri, 29 Aug 2025 11:39:42 +0000
Message-ID: <19036-ef3954ff85feefe2@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      19036
Logged by:          Chi Zhang
Email address:      798604270@qq.com
PostgreSQL version: 17.5
Operating system:   ubuntu 24.04 with docker
Description:        

Hi,

In the following test case, the `EXECUTE` statement will fail with an error
`result of range union would not be contiguous`. The final SELECT query
should return 1 row as there is only one value `1` in  t1.c0 and only one
value `1` in t3.c0, however, the query returns 0 rows.

```
SET plan_cache_mode = force_generic_plan;
CREATE TABLE t1(c0 REAL);
CREATE TABLE t3(c0 bigserial, c1 int4range);
PREPARE prepare_query (int4range, int4range, int4range, int4range,
int4range, int4range, int4range, int4range, int4range, int4range, int4range,
int4range, int4range, int4range, int4range, int4range, int4range) AS INSERT
INTO t3(c1) VALUES(((range_merge((((($3)-($4)))*($5)),
(((($6)+($7)))-((($8)-($9))))))-((((((($10)-($11)))-((($12)*($13)))))*((((($14)*($15)))+((($16)-($17)))))))));
EXECUTE prepare_query('(-556931823,1276777813)'::int4range,
'(-571202662,1382275249]'::int4range, '[507243772,1979226805)'::int4range,
'(-886673458,-886673458]'::int4range, '[-602190450,-571202662]'::int4range,
'(-1179115181,-994816467]'::int4range,
'[-1324483627,-617195673]'::int4range, '(-1920488796,362367315]'::int4range,
'(-1920488796,-974159112]'::int4range, '(-1511616986,309266836)'::int4range,
'[264292163,2029512724]'::int4range, '(-1235934435,-274850186]'::int4range,
'[510315686,1121320469)'::int4range, '(52072425,1543185664)'::int4range,
'[13120838,1960723456]'::int4range, '[-1240013782,-395016816]'::int4range,
'(1151766089,2106918647)'::int4range);
DEALLOCATE prepare_query;
INSERT INTO t1(c0) VALUES(CAST(CAST(1 AS INT) AS INT));
INSERT INTO t3(c1) VALUES('[-761818403,793731611]'::int4range);
SELECT t1.c0 FROM t3, t1 WHERE (CAST(t1.c0 AS INT)) IN (t3.c0);
```

If you remove the `SET plan_cache_mode = force_generic_plan;` option or the
prepared statement, the query will return correct result.



view thread (6+ messages)  latest in thread

Message-ID: <19036-ef3954ff85feefe2@postgresql.org>
Permalink:  ../19036-ef3954ff85feefe2@postgresql.org/
Also on:    postgresql.org/message-id/19036-ef3954ff85feefe2@postgresql.org

 · 

reply

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, 798604270@qq.com
  Subject: Re: BUG #19036: Failed prepared INSERT statement make another SELECT query generate wrong result
  In-Reply-To: <19036-ef3954ff85feefe2@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