When using simple protocol (raw SQL, no bind parameters), COALESCE(NULL, integer_column) fails with:
ASSIGNMENT_CAST: target is of type integer but expression is of type text: coalesce(NULL,table.column)
Standard PostgreSQL infers the type of NULL from context in COALESCE expressions. DoltgreSQL appears to default untyped NULL to text.
Reproduction
CREATE TABLE test_coalesce (id UUID PRIMARY KEY, val INTEGER NOT NULL DEFAULT 0);
INSERT INTO test_coalesce VALUES ('00000000-0000-0000-0000-000000000001', 42);
UPDATE test_coalesce SET val = COALESCE(NULL, val) WHERE id = '00000000-0000-0000-0000-000000000001';
-- Expected: no-op, val stays 42
-- Actual: ASSIGNMENT_CAST error
Workaround
Use CASE WHEN FALSE THEN NULL ELSE val END instead of COALESCE(NULL, val), or use explicit cast COALESCE(NULL::integer, val).
Notes
Same issue affects DATE columns: COALESCE(NULL, date_column) also fails.
When using simple protocol (raw SQL, no bind parameters),
COALESCE(NULL, integer_column)fails with:Standard PostgreSQL infers the type of NULL from context in COALESCE expressions. DoltgreSQL appears to default untyped NULL to text.
Reproduction
Workaround
Use
CASE WHEN FALSE THEN NULL ELSE val ENDinstead ofCOALESCE(NULL, val), or use explicit castCOALESCE(NULL::integer, val).Notes
Same issue affects DATE columns:
COALESCE(NULL, date_column)also fails.