diff --git a/pkg/sql/logictest/testdata/logic_test/views b/pkg/sql/logictest/testdata/logic_test/views index 37e710c2d264..8c35a3ad6736 100644 --- a/pkg/sql/logictest/testdata/logic_test/views +++ b/pkg/sql/logictest/testdata/logic_test/views @@ -140,6 +140,27 @@ CREATE DATABASE test2 statement ok SET DATABASE = test2 +statement ok +CREATE VIEW t1 AS SELECT ARRAY[]:::STRING[]; +CREATE VIEW t2 AS SELECT ARRAY[1,2,3]:::INT[]; + + +query TT colnames +SHOW CREATE VIEW t1 +---- +table_name create_statement +t1 CREATE VIEW public.t1 ( + "array" + ) AS SELECT ARRAY[]:::STRING[] + +query TT colnames +SHOW CREATE VIEW t2 +---- +table_name create_statement +t2 CREATE VIEW public.t2 ( + "array" + ) AS SELECT ARRAY[1:::INT8, 2:::INT8, 3:::INT8]:::INT8[] + query II colnames,rowsort SELECT * FROM test.v1 ---- diff --git a/pkg/sql/sem/tree/expr.go b/pkg/sql/sem/tree/expr.go index eaecbf0ce31f..c8d56c0cfec6 100644 --- a/pkg/sql/sem/tree/expr.go +++ b/pkg/sql/sem/tree/expr.go @@ -1595,6 +1595,13 @@ func (node *AnnotateTypeExpr) Format(ctx *FmtCtx) { switch node.SyntaxMode { case AnnotateShort: exprFmtWithParen(ctx, node.Expr) + // The Array format function handles adding type annotations for this case. + // We short circuit here to prevent double type annotation. + if arrayExpr, ok := node.Expr.(*Array); ok { + if ctx.HasFlags(FmtParsable) && arrayExpr.typ != nil { + return + } + } ctx.WriteString(":::") ctx.FormatTypeReference(node.Type)