Skip to content

Conversation

@mbrandonw
Copy link
Member

Right now map on QueryExpression just side steps the type checker to allow dealing with the "unwrapped" query value. This mostly works because SQLite's type system is so lax.

However, if you perform a map { … } and invoke a database function under the hood, you can accidentally feed a NULL value to something that requires non-NULL. The fix is to completely side-step invoking the transform function if the underlying value is NULL.

@mbrandonw mbrandonw requested review from Copilot and stephencelis and removed request for Copilot November 4, 2025 16:16
SQLQueryExpression(transform(SQLQueryExpression(queryFragment)).queryFragment)
SQLQueryExpression(
"""
IIF(\(self), \(transform(SQLQueryExpression(queryFragment))), NULL)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hoped I could use CASE/WHEN/THEN here to be SQL compatible, but apparently the cases are not lazy. They are evaluated even if their conditions are false. IIF on the other hand is lazy, and so we really can avoid invoking the transform if it is NULL.

@stephencelis stephencelis merged commit 9c84335 into main Nov 4, 2025
3 checks passed
@stephencelis stephencelis deleted the db-function-representation branch November 4, 2025 17:59
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.

3 participants