Skip to content

fix: recursively process all expressions in COALESCE arguments#53

Merged
exAspArk merged 1 commit intoBemiHQ:mainfrom
JC1738:fix/coalesce
Nov 4, 2025
Merged

fix: recursively process all expressions in COALESCE arguments#53
exAspArk merged 1 commit intoBemiHQ:mainfrom
JC1738:fix/coalesce

Conversation

@JC1738
Copy link
Copy Markdown
Contributor

@JC1738 JC1738 commented Nov 4, 2025

The COALESCE expression handler was only processing SubLink (nested SELECT)
arguments, but not other expression types like TypeCast nodes. This caused
queries with '[]'::jsonb inside COALESCE to fail with "Type jsonb does not
exist" errors, since the ::jsonb->::json remapping never occurred.

Changed COALESCE handler to recursively process all argument types using
remappedExpressions(), matching the pattern used for function calls and
boolean expressions. This ensures type casts and other expressions are
properly remapped regardless of nesting context.

Added test coverage for COALESCE with jsonb type casts.

This commit addresses two issues with PostgreSQL compatibility:

1. COALESCE expression handling:
   - Recursively process all expressions in COALESCE arguments
   - Handles nested function calls within COALESCE (e.g., jsonb_array_length)
   - Previously only processed SubLink nodes, now handles all expression types

2. jsonb_array_length return type:
   - Cast result to INTEGER to match PostgreSQL's int4 return type (OID 23)
   - PostgreSQL's jsonb_array_length() returns INTEGER, not BIGINT or UBIGINT
   - Updated test expectations from XID8OID (5069) to Int4OID (23)

Tests added:
- COALESCE with JSONB types
- jsonb_array_length with COALESCE expressions
@exAspArk
Copy link
Copy Markdown
Member

exAspArk commented Nov 4, 2025

@JC1738 thank you! This looks great! 🙌

@exAspArk exAspArk merged commit 8b79593 into BemiHQ:main Nov 4, 2025
1 check passed
@JC1738 JC1738 deleted the fix/coalesce branch November 11, 2025 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants