Description
COUNT(*) returns incorrect values when queried via the PostgreSQL extended query protocol (binary format). The result appears to be sent as text bytes instead of binary integer encoding.
Reproduction
Using sqlx (Rust PostgreSQL driver) with prepared statements (extended query protocol):
SELECT COUNT(*) FROM some_table WHERE some_column = $1
When the table has 0 rows matching, the binary result is interpreted as 48 (which is the ASCII value of '0').
When the table has 1 row matching, the result is 49 (ASCII value of '1').
The same query via psql (simple query protocol) returns the correct value (0 and 1 respectively).
Environment
- DoltgreSQL v0.55.2
- Client: sqlx 0.8 (Rust) with
statement_cache_capacity(0)
- Connection: standard PostgreSQL wire protocol
Workaround
Explicit cast forces correct binary encoding:
SELECT COUNT(*)::bigint FROM some_table WHERE some_column = $1
Related Issues
This is the same class of binary framing bug as:
Description
COUNT(*)returns incorrect values when queried via the PostgreSQL extended query protocol (binary format). The result appears to be sent as text bytes instead of binary integer encoding.Reproduction
Using sqlx (Rust PostgreSQL driver) with prepared statements (extended query protocol):
When the table has 0 rows matching, the binary result is interpreted as 48 (which is the ASCII value of
'0').When the table has 1 row matching, the result is 49 (ASCII value of
'1').The same query via
psql(simple query protocol) returns the correct value (0 and 1 respectively).Environment
statement_cache_capacity(0)Workaround
Explicit cast forces correct binary encoding:
Related Issues
This is the same class of binary framing bug as: