From 324adc074f2297a725dddb905ae86dc3ca78b107 Mon Sep 17 00:00:00 2001 From: Jordan Lewis Date: Fri, 8 Feb 2019 16:46:27 -0500 Subject: [PATCH] sql: fix missing null check in json sub array Release note (bug fix): fix panic when subtracting an array containing null from a json datum. --- pkg/sql/logictest/testdata/logic_test/json | 6 ++++++ pkg/sql/sem/tree/eval.go | 3 +++ 2 files changed, 9 insertions(+) diff --git a/pkg/sql/logictest/testdata/logic_test/json b/pkg/sql/logictest/testdata/logic_test/json index d95f491d6808..486d1c137c19 100644 --- a/pkg/sql/logictest/testdata/logic_test/json +++ b/pkg/sql/logictest/testdata/logic_test/json @@ -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'] diff --git a/pkg/sql/sem/tree/eval.go b/pkg/sql/sem/tree/eval.go index e9041e6b1ef4..ec58ed2710ba 100644 --- a/pkg/sql/sem/tree/eval.go +++ b/pkg/sql/sem/tree/eval.go @@ -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 {