Skip to content

Commit

Permalink
Merge #40626
Browse files Browse the repository at this point in the history
40626: sql/sem/builtins: fix width_bucket for 0-length arrays r=mjibson a=mjibson

Fixes #40623

Release note (bug fix): width_bucket no longer errors on 0-length arrays

Co-authored-by: Matt Jibson <matt.jibson@gmail.com>
  • Loading branch information
craig[bot] and maddyblue committed Sep 10, 2019
2 parents 404cbf9 + de08130 commit 3ad8bda
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/builtin_function
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sem/builtins/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

Expand Down

0 comments on commit 3ad8bda

Please sign in to comment.