diff --git a/internal/function_register.go b/internal/function_register.go index 2dd46a1..df45895 100644 --- a/internal/function_register.go +++ b/internal/function_register.go @@ -427,6 +427,9 @@ func RegisterFunctions(conn *sqlite3.SQLiteConn) error { if err != nil { return "", err } + if decoded == nil { + return "[]", nil + } array, err := decoded.ToArray() if err != nil { return "", err diff --git a/query_test.go b/query_test.go index fa854be..6ee91b7 100644 --- a/query_test.go +++ b/query_test.go @@ -2527,6 +2527,22 @@ FROM }, }, }, + // Regression test for goccy/go-zetasqlite#179 + { + name: "null array scan", + query: ` +WITH file AS ( + SELECT 1 AS file_id, ARRAY["r", "w"] AS modes + UNION ALL SELECT 2, ARRAY["w"] +) +SELECT id, +(SELECT mode FROM UNNEST(modes) AS mode WHERE mode = 'w') IS NOT NULL AS write_mode, +(SELECT mode FROM UNNEST(modes) AS mode WHERE mode = 'r') IS NOT NULL AS read_mode +FROM UNNEST([1, 2, 3]) id +LEFT JOIN file on file.file_id = id`, + expectedRows: [][]interface{}{{int64(1), true, true}, {int64(2), true, false}, {int64(3), false, false}}, + }, + { name: "array_reverse function", query: `