Re: BUG #19033: Inconsistency between prepared statement and normal statement when cast bit to integer

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: 798604270@qq.com
Cc: pgsql-bugs@lists.postgresql.org
Date: 2025-08-27T14:54:55Z
Lists: pgsql-bugs
PG Bug reporting form <noreply@postgresql.org> writes:
> 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

The reason that fails is that EvaluateParams uses assignment-coercion
semantics, which is more limited in what it will allow than an
explicit coercion.  I think this is correct behavior.  The system
should not silently perform cross-type-category casts --- too much
risk of unintended results.

			regards, tom lane