github.com/cockroachdb/cockroachdb-parser@v0.23.3-0.20240213214944-911057d40c9a/pkg/sql/sem/tree/table_ref.go (about) 1 // Copyright 2017 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 tree 12 13 import "github.com/cockroachdb/cockroachdb-parser/pkg/sql/sem/catid" 14 15 // ID is a custom type for {Database,Table}Descriptor IDs. 16 type ID = catid.ColumnID 17 18 // ColumnID is a custom type for ColumnDescriptor IDs. 19 type ColumnID = catid.ColumnID 20 21 // TableRef represents a numeric table reference. 22 // (Syntax !NNN in SQL.) 23 type TableRef struct { 24 // TableID is the descriptor ID of the requested table. 25 TableID int64 26 27 // ColumnIDs is the list of column IDs requested in the table. 28 // Note that a nil array here means "unspecified" (all columns) 29 // whereas an array of length 0 means "zero columns". 30 // Lists of zero columns are not supported and will throw an error. 31 Columns []ColumnID 32 33 // As determines the names that can be used in the surrounding query 34 // to refer to this source. 35 As AliasClause 36 } 37 38 // Format implements the NodeFormatter interface. 39 func (n *TableRef) Format(ctx *FmtCtx) { 40 ctx.Printf("[%d", n.TableID) 41 if n.Columns != nil { 42 ctx.WriteByte('(') 43 for i, c := range n.Columns { 44 if i > 0 { 45 ctx.WriteString(", ") 46 } 47 ctx.Printf("%d", c) 48 } 49 ctx.WriteByte(')') 50 } 51 if n.As.Alias != "" { 52 ctx.WriteString(" AS ") 53 ctx.FormatNode(&n.As) 54 } 55 ctx.WriteByte(']') 56 } 57 func (n *TableRef) String() string { return AsString(n) } 58 59 // tableExpr implements the TableExpr interface. 60 func (n *TableRef) tableExpr() {}