Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
52416: sql: fix internal error when trying to parse strings as arrays r=RaduBerinde a=RaduBerinde

The parse-constant-as-type code was allowing a desired type of `Array[Any]`, and
we can't parse elements as `Any`. This resulted in an internal error, rather
than a normal query error.

Fixes cockroachdb#52134.

Release note (bug fix): Fixed an internal error involving string literals used
as arrays.

Co-authored-by: Radu Berinde <[email protected]>
  • Loading branch information
craig[bot] and RaduBerinde committed Aug 10, 2020
2 parents dd88cc2 + 32522ea commit 7fa9c67
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/array
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ SELECT ARRAY['a', 'b', 'c'][0]
----
NULL

# Regression test for #52134: make sure this is not an internal error.
query error cannot subscript type string because it is not an array
SELECT '{a,b,c}'[0]

query T
SELECT (ARRAY['a', 'b', 'c'])[2]
----
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/sem/tree/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func typeCheckConstant(
ctx context.Context, semaCtx *SemaContext, c Constant, desired *types.T,
) (ret TypedExpr, err error) {
avail := c.AvailableTypes()
if desired.Family() != types.AnyFamily {
if !desired.IsAmbiguous() {
for _, typ := range avail {
if desired.Equivalent(typ) {
return c.ResolveAsType(ctx, semaCtx, desired)
Expand Down

0 comments on commit 7fa9c67

Please sign in to comment.