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