Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
34757: sql: fix missing null check in json sub array r=jordanlewis a=jordanlewis

Fixes cockroachdb#34756.

Release note (bug fix): fix panic when subtracting an array containing
null from a json datum.

Co-authored-by: Jordan Lewis <[email protected]>
  • Loading branch information
craig[bot] and jordanlewis committed Feb 8, 2019
2 parents 3981ac6 + 324adc0 commit 40e4035
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/json
Original file line number Diff line number Diff line change
Expand Up @@ -665,5 +665,11 @@ SELECT '{"b": [], "c": {"a": "b"}}'::JSONB - array['a'];
----
{"b": [], "c": {"a": "b"}}

# Regression test for #34756.
query T
SELECT '{"b": [], "c": {"a": "b"}}'::JSONB - array['foo', NULL]
----
{"b": [], "c": {"a": "b"}}

statement error pgcode 22P02 a path element is not an integer: foo
SELECT '{"a": {"b": ["foo"]}}'::JSONB #- ARRAY['a', 'b', 'foo']
3 changes: 3 additions & 0 deletions pkg/sql/sem/tree/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,9 @@ var BinOps = map[BinaryOperator]binOpOverload{
arr := *MustBeDArray(right)

for _, str := range arr.Array {
if str == DNull {
continue
}
var err error
j, _, err = j.RemoveString(string(MustBeDString(str)))
if err != nil {
Expand Down

0 comments on commit 40e4035

Please sign in to comment.