From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: 798604270@qq.com
Subject: BUG #19033: Inconsistency between prepared statement and normal statement when cast bit to integer
Date: Wed, 27 Aug 2025 07:01:27 +0000
Message-ID: <19033-9eec36049d7363e8@postgresql.org> (raw)
The following bug has been logged on the website:
Bug reference: 19033
Logged by: Chi Zhang
Email address: 798604270@qq.com
PostgreSQL version: 18beta3
Operating system: ubuntu 24.04 with docker
Description:
Hi,
In the normal statement, casting a bit value to INT is allowed, but in a
prepared statement, it will trigger an error.
In the following test case, the first query will return 15, but the EXECUTE
statement will trigger an error: parameter $1 of type bit cannot be coerced
to the expected type integer
```
SELECT (B'1111')::INT;
int4
------
15
(1 row)
PREPARE prepare_query (unknown) AS SELECT $1::INT;
EXECUTE prepare_query(B'1111');
ERROR: parameter $1 of type bit cannot be coerced to the expected type
integer
```
If I modify the unknown type to bit, then the query can execute successfully
and return 15.
```
PREPARE prepare_query (bit) AS SELECT $1::INT;
EXECUTE prepare_query(B'1111');
int4
------
15
(1 row)
```
I also find if I first cast B'1111' to bit and then cast it to integer, it
will become 1. But the correct result should be 15.
```
SELECT ((B'1111')::bit)::INT;
int4
------
1
(1 row)
```
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 #19033: Inconsistency between prepared statement and normal statement when cast bit to integer
In-Reply-To: <19033-9eec36049d7363e8@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