Description
SELECT EXISTS(SELECT 1 FROM ...) returns a value with type INT2 (smallint) instead of BOOL, which is the correct PostgreSQL behavior. This breaks any typed PostgreSQL client that expects the standard return type.
Reproduction
-- In PostgreSQL:
SELECT EXISTS(SELECT 1 FROM pg_catalog.pg_tables WHERE tablename = 'test');
-- Returns: true (type: bool)
-- In DoltgreSQL:
SELECT EXISTS(SELECT 1 FROM pg_catalog.pg_tables WHERE tablename = 'test');
-- Returns: 1 (type: int2)
Impact
Any client library that uses typed query results will fail. For example, in Rust with SQLx:
// This works in PostgreSQL but fails in DoltgreSQL:
let exists = sqlx::query_scalar::<_, bool>(
"SELECT EXISTS(SELECT 1 FROM users WHERE email = $1)"
)
.bind(&email)
.fetch_one(&pool)
.await?;
Error: mismatched types; Rust type boolis not compatible with SQL typeINT2``
Workaround
We currently rewrite all EXISTS queries to use COUNT(*):
-- Instead of:
SELECT EXISTS(SELECT 1 FROM users WHERE email = $1)
-- We use:
SELECT COUNT(*) FROM users WHERE email = $1
-- and then check > 0 in application code
This is a significant migration burden — in our codebase we have 22+ locations that need this workaround.
Expected behavior
SELECT EXISTS(...) should return BOOL (OID 16), matching PostgreSQL behavior.
Environment
- DoltgreSQL: latest Docker image (
dolthub/doltgresql:latest)
- Client: SQLx 0.8 (Rust), but affects any typed PostgreSQL client
Description
SELECT EXISTS(SELECT 1 FROM ...)returns a value with typeINT2(smallint) instead ofBOOL, which is the correct PostgreSQL behavior. This breaks any typed PostgreSQL client that expects the standard return type.Reproduction
Impact
Any client library that uses typed query results will fail. For example, in Rust with SQLx:
Error:
mismatched types; Rust typeboolis not compatible with SQL typeINT2``Workaround
We currently rewrite all EXISTS queries to use COUNT(*):
This is a significant migration burden — in our codebase we have 22+ locations that need this workaround.
Expected behavior
SELECT EXISTS(...)should returnBOOL(OID 16), matching PostgreSQL behavior.Environment
dolthub/doltgresql:latest)