Skip to content

Commit e9de003

Browse files
committed
sql: fix first contains/contained by array op null panic
We encountered an error in the binary op evaluator for NULL values in an array with the first contains (?@>) and first contained by (?<@) operators for ltree. This is now handled. Fixes: #152323 Epic: None Release note: None
1 parent 1aabeeb commit e9de003

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/sql/sem/eval/binary_op.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,9 @@ func (e *evaluator) EvalFirstContainedByLTreeOp(
349349
array := tree.MustBeDArray(a)
350350
elem := tree.MustBeDLTree(b)
351351

352+
if array.HasNulls {
353+
return nil, pgerror.New(pgcode.NullValueNotAllowed, "array must not contain nulls")
354+
}
352355
for _, d := range array.Array {
353356
if elem.LTree.Contains(tree.MustBeDLTree(d).LTree) {
354357
return tree.MustBeDLTree(d), nil
@@ -408,6 +411,9 @@ func (e *evaluator) EvalFirstContainsLTreeOp(
408411
array := tree.MustBeDArray(a)
409412
elem := tree.MustBeDLTree(b)
410413

414+
if array.HasNulls {
415+
return nil, pgerror.New(pgcode.NullValueNotAllowed, "array must not contain nulls")
416+
}
411417
for _, d := range array.Array {
412418
if tree.MustBeDLTree(d).LTree.Contains(elem.LTree) {
413419
return tree.MustBeDLTree(d), nil

pkg/sql/sem/eval/eval_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,8 @@ func TestEvalError(t *testing.T) {
351351
{`B'1001' & B'101'`, `cannot AND bit strings of different sizes`},
352352
{`B'1001' | B'101'`, `cannot OR bit strings of different sizes`},
353353
{`B'1001' # B'101'`, `cannot XOR bit strings of different sizes`},
354+
{`ARRAY['A.B.C', NULL]::LTREE[] ?@> 'A.B.C'`, `array must not contain nulls`},
355+
{`ARRAY['A.B.C', NULL]::LTREE[] ?<@ 'A.B.C'`, `array must not contain nulls`},
354356
}
355357
ctx := context.Background()
356358
for _, d := range testData {

0 commit comments

Comments
 (0)