From de08130b7e06db82ec4ddcda0d19291fe64bc6f8 Mon Sep 17 00:00:00 2001 From: Matt Jibson Date: Tue, 10 Sep 2019 00:18:28 -0600 Subject: [PATCH] sql/sem/builtins: fix width_bucket for 0-length arrays Fixes #40623 Release note (bug fix): width_bucket no longer errors on 0-length arrays --- pkg/sql/logictest/testdata/logic_test/builtin_function | 6 ++++++ pkg/sql/sem/builtins/builtins.go | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pkg/sql/logictest/testdata/logic_test/builtin_function b/pkg/sql/logictest/testdata/logic_test/builtin_function index 48f66f3cacf9..185be368e7b6 100644 --- a/pkg/sql/logictest/testdata/logic_test/builtin_function +++ b/pkg/sql/logictest/testdata/logic_test/builtin_function @@ -2265,6 +2265,12 @@ SELECT width_bucket(now(), array['yesterday', 'today', 'tomorrow']::timestamptz[ query error pq: width_bucket\(\): Operand and thresholds must be of the same type SELECT width_bucket(1, array['a', 'h', 'l', 'z']); +# Regression for #40623 +query I +SELECT width_bucket(1, array[]::int[]); +---- +0 + # Sanity check pg_type_is_visible. query BBB SELECT pg_type_is_visible('int'::regtype), pg_type_is_visible(NULL), pg_type_is_visible(99999) diff --git a/pkg/sql/sem/builtins/builtins.go b/pkg/sql/sem/builtins/builtins.go index b1ba4314296c..499c290dc438 100644 --- a/pkg/sql/sem/builtins/builtins.go +++ b/pkg/sql/sem/builtins/builtins.go @@ -2408,7 +2408,7 @@ may increase either contention or retry errors, or both.`, operand := args[0] thresholds := tree.MustBeDArray(args[1]) - if !operand.ResolvedType().Equivalent(thresholds.Array[0].ResolvedType()) { + if !operand.ResolvedType().Equivalent(thresholds.ParamTyp) { return tree.NewDInt(0), errors.New("Operand and thresholds must be of the same type") }