Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: remove extra type hint from SHOW CREATE VIEW #95679

Merged
merged 1 commit into from
Feb 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/views
Original file line number Diff line number Diff line change
Expand Up @@ -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
----
Expand Down
7 changes: 7 additions & 0 deletions pkg/sql/sem/tree/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down