Skip to content

sql: add TRY_CAST to handle errors in (most) casts - #38845

Draft
mgree wants to merge 6 commits into
MaterializeInc:mainfrom
mgree:trycast
Draft

mgree wants to merge 6 commits into
MaterializeInc:mainfrom
mgree:trycast

Conversation

@mgree

@mgree mgree commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Motivation

Closes https://linear.app/materializeinc/issue/CS-334/safe-cast-try-cast-function-for-handling-bad-data-on-ingest.

Description

A TRY_CAST(<expr> AS <type>) evaluates <expr> once and attempts to cast it to <type>. While casts can fail (e.g., not every string is an integer!), TRY_CAST will detect failures and produce NULL instead.

Verification

Extensive testing for each cast: good values stay good, bad values turn into NULL. This testing is in SLTs, proptests, and concrete unit tests with chosen values.

@mgree
mgree force-pushed the trycast branch 5 times, most recently from 4b88aa2 to a1477a7 Compare September 15, 2026 15:48
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.

1 participant