Problems / TRY_CAST the Junk Away / Editorial
TRY_CAST(value AS DOUBLE)
'N/A'
'error'
''
'twelve'
COUNT
COUNT(*)
COUNT(expr)
COUNT(TRY_CAST(...))
valid_count
COUNT(*) - COUNT(TRY_CAST(...))
junk_count
AVG(TRY_CAST(...))
AVG
sensor_id
The difference between CAST and TRY_CAST is the difference between a pipeline that crashes on the first bad row and one that quantifies its dirty data. Because failed casts become NULLs, the whole valid/junk/average report falls out of standard aggregate semantics: COUNT(col) vs COUNT(*) and NULL-ignoring AVG. The classic mistake is treating junk as zero — that silently drags the average down; NULL is the honest answer.
CAST
TRY_CAST
COUNT(col)
Solve TRY_CAST the Junk Away yourself →