diff --git a/pkg/sql/logictest/testdata/logic_test/json b/pkg/sql/logictest/testdata/logic_test/json index da291dc6de93..6f645ebb22af 100644 --- a/pkg/sql/logictest/testdata/logic_test/json +++ b/pkg/sql/logictest/testdata/logic_test/json @@ -607,6 +607,15 @@ SELECT true FROM x WHERE j->'a' @> '2'::JSONB ---- true +query T +SELECT j FROM x WHERE j ?| ARRAY[NULL] +---- + +query T +SELECT j FROM x WHERE j ?& ARRAY[NULL::STRING] +---- +{"a": [1, 2, 3]} + query T SELECT '{"foo": {"bar": 1}}'::JSONB #- ARRAY['foo', 'bar'] ---- diff --git a/pkg/sql/rowenc/index_encoding.go b/pkg/sql/rowenc/index_encoding.go index 033ba11c6cfe..2abddbf8a37e 100644 --- a/pkg/sql/rowenc/index_encoding.go +++ b/pkg/sql/rowenc/index_encoding.go @@ -704,8 +704,11 @@ func EncodeExistsInvertedIndexSpans( } var expr inverted.Expression for _, d := range val.(*tree.DArray).Array { - s := string(*d.(*tree.DString)) - newExpr, err := json.EncodeExistsInvertedIndexSpans(nil /* inKey */, s) + ds, ok := tree.AsDString(d) + if !ok { + continue + } + newExpr, err := json.EncodeExistsInvertedIndexSpans(nil /* inKey */, string(ds)) if err != nil { return nil, err }