github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/sql/sem/tree/values.go (about)

     1  // Copyright 2012, Google Inc. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in licenses/BSD-vitess.txt.
     4  
     5  // Portions of this file are additionally subject to the following
     6  // license and copyright.
     7  //
     8  // Copyright 2015 The Cockroach Authors.
     9  //
    10  // Use of this software is governed by the Business Source License
    11  // included in the file licenses/BSL.txt.
    12  //
    13  // As of the Change Date specified in that file, in accordance with
    14  // the Business Source License, use of this software will be governed
    15  // by the Apache License, Version 2.0, included in the file
    16  // licenses/APL.txt.
    17  
    18  // This code was derived from https://github.com/youtube/vitess.
    19  
    20  package tree
    21  
    22  // ValuesClause represents a VALUES clause.
    23  type ValuesClause struct {
    24  	Rows []Exprs
    25  }
    26  
    27  // Format implements the NodeFormatter interface.
    28  func (node *ValuesClause) Format(ctx *FmtCtx) {
    29  	ctx.WriteString("VALUES ")
    30  	comma := ""
    31  	for i := range node.Rows {
    32  		ctx.WriteString(comma)
    33  		ctx.WriteByte('(')
    34  		ctx.FormatNode(&node.Rows[i])
    35  		ctx.WriteByte(')')
    36  		comma = ", "
    37  	}
    38  }
    39  
    40  // ValuesClauseWithNames is a VALUES clause that has been annotated with column
    41  // names. This is only produced at plan time, never by the parser. It's used to
    42  // pass column names to the VALUES planNode, so it can produce intelligible
    43  // error messages during value type checking.
    44  type ValuesClauseWithNames struct {
    45  	ValuesClause
    46  
    47  	// Names is a list of the column names that each tuple in the ValuesClause
    48  	// corresponds to.
    49  	Names NameList
    50  }