github.com/matrixorigin/matrixone@v1.2.0/pkg/sql/parsers/tree/insert.go (about) 1 // Copyright 2021 Matrix Origin 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package tree 16 17 // the INSERT statement. 18 type Insert struct { 19 statementImpl 20 Table TableExpr 21 22 Accounts IdentifierList 23 PartitionNames IdentifierList 24 Columns IdentifierList 25 Rows *Select 26 OnDuplicateUpdate UpdateExprs 27 IsRestore bool 28 FromDataTenantID uint32 29 } 30 31 func (node *Insert) Format(ctx *FmtCtx) { 32 ctx.WriteString("insert into ") 33 node.Table.Format(ctx) 34 35 if node.PartitionNames != nil { 36 ctx.WriteString(" partition(") 37 node.PartitionNames.Format(ctx) 38 ctx.WriteByte(')') 39 } 40 41 if node.Columns != nil { 42 ctx.WriteString(" (") 43 node.Columns.Format(ctx) 44 ctx.WriteByte(')') 45 } 46 if node.Accounts != nil { 47 ctx.WriteString(" accounts(") 48 node.Accounts.Format(ctx) 49 ctx.WriteByte(')') 50 } 51 if node.Rows != nil { 52 ctx.WriteByte(' ') 53 node.Rows.Format(ctx) 54 } 55 if len(node.OnDuplicateUpdate) > 0 { 56 ctx.WriteString(" on duplicate key update ") 57 node.OnDuplicateUpdate.Format(ctx) 58 } 59 } 60 61 func (node *Insert) GetStatementType() string { return "Insert" } 62 func (node *Insert) GetQueryType() string { return QueryTypeDML } 63 64 func NewInsert(t TableExpr, c IdentifierList, r *Select, p IdentifierList) *Insert { 65 return &Insert{ 66 Table: t, 67 Columns: c, 68 Rows: r, 69 PartitionNames: p, 70 } 71 } 72 73 type Assignment struct { 74 Column Identifier 75 Expr Expr 76 }