There's currently special handling for case statements such that expressions for a case are executed only when their condition is matched.
In contrast to this behavior, the IF() function will execute its case expressions prior to evaluating the input condition.
This test case shows the failing behavior:
{
name: "if with case that causes errors",
query: `SELECT IF(FALSE, SPLIT(CAST(NULL AS STRING), " ")[OFFSET(0)], "false")`,
expectedRows: [][]interface{}{{"false"}},
},
returns
=== RUN TestQuery/if_with_case_that_causes_errors
query_test.go:5948: OFFSET(0) is out of range
Passing CASE test:
{
name: "case with case that causes errors",
query: `SELECT CASE WHEN FALSE THEN SPLIT(CAST(NULL AS STRING), " ")[OFFSET(0)] ELSE "false" END`,
expectedRows: [][]interface{}{{"false"}},
},
There's currently special handling for case statements such that expressions for a case are executed only when their condition is matched.
In contrast to this behavior, the
IF()
function will execute its case expressions prior to evaluating the input condition.This test case shows the failing behavior:
returns
Passing
CASE
test: