github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/opt/testutils/testcat/create_view.go (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 package testcat 12 13 import "github.com/cockroachdb/cockroach/pkg/sql/sem/tree" 14 15 // CreateView creates a test view from a parsed DDL statement and adds it to the 16 // catalog. 17 func (tc *Catalog) CreateView(stmt *tree.CreateView) *View { 18 // Update the view name to include catalog and schema if not provided. 19 tc.qualifyTableName(&stmt.Name) 20 21 fmtCtx := tree.NewFmtCtx(tree.FmtParsable) 22 stmt.AsSource.Format(fmtCtx) 23 24 view := &View{ 25 ViewID: tc.nextStableID(), 26 ViewName: stmt.Name, 27 QueryText: fmtCtx.CloseAndGetString(), 28 ColumnNames: stmt.ColumnNames, 29 } 30 31 // Add the new view to the catalog. 32 tc.AddView(view) 33 34 return view 35 }