Skip to content

COUNT(*) returns wrong value via binary protocol (extended query) #2362

@johannesdb

Description

@johannesdb

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:

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions