本文整理汇总了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.Insert.NormalizeUnqualifiedColumnItem方法的典型用法代码示例。如果您正苦于以下问题:Golang Insert.NormalizeUnqualifiedColumnItem方法的具体用法?Golang Insert.NormalizeUnqualifiedColumnItem怎么用?Golang Insert.NormalizeUnqualifiedColumnItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cockroachdb/cockroach/pkg/sql/parser.Insert
的用法示例。
在下文中一共展示了Insert.NormalizeUnqualifiedColumnItem方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Insert
//.........这里部分代码省略.........
}
// Analyze the expressions for column information and typing.
desiredTypesFromSelect := make([]parser.Type, len(cols))
for i, col := range cols {
desiredTypesFromSelect[i] = col.Type.ToDatumType()
}
// Create the plan for the data source.
// This performs type checking on source expressions, collecting
// types for placeholders in the process.
rows, err := p.newPlan(insertRows, desiredTypesFromSelect, false)
if err != nil {
return nil, err
}
if expressions := len(rows.Columns()); expressions > numInputColumns {
return nil, fmt.Errorf("INSERT error: table %s has %d columns but %d values were supplied", n.Table, numInputColumns, expressions)
}
fkTables := tablesNeededForFKs(*en.tableDesc, CheckInserts)
if err := p.fillFKTableMap(fkTables); err != nil {
return nil, err
}
ri, err := makeRowInserter(p.txn, en.tableDesc, fkTables, cols, checkFKs)
if err != nil {
return nil, err
}
var tw tableWriter
if n.OnConflict == nil {
tw = &tableInserter{ri: ri, autoCommit: autoCommit}
} else {
updateExprs, conflictIndex, err := upsertExprsAndIndex(en.tableDesc, *n.OnConflict, ri.insertCols)
if err != nil {
return nil, err
}
if n.OnConflict.DoNothing {
// TODO(dan): Postgres allows ON CONFLICT DO NOTHING without specifying a
// conflict index, which means do nothing on any conflict. Support this if
// someone needs it.
tw = &tableUpserter{ri: ri, conflictIndex: *conflictIndex}
} else {
names, err := p.namesForExprs(updateExprs)
if err != nil {
return nil, err
}
// Also include columns that are inactive because they should be
// updated.
updateCols := make([]sqlbase.ColumnDescriptor, len(names))
for i, n := range names {
c, err := n.NormalizeUnqualifiedColumnItem()
if err != nil {
return nil, err
}
status, idx, err := en.tableDesc.FindColumnByName(c.ColumnName)
if err != nil {
return nil, err
}
if status == sqlbase.DescriptorActive {
updateCols[i] = en.tableDesc.Columns[idx]
} else {
updateCols[i] = *en.tableDesc.Mutations[idx].GetColumn()
}
}
helper, err := p.makeUpsertHelper(tn, en.tableDesc, ri.insertCols, updateCols, updateExprs, conflictIndex)
if err != nil {
return nil, err
}
fkTables := tablesNeededForFKs(*en.tableDesc, CheckUpdates)
if err := p.fillFKTableMap(fkTables); err != nil {
return nil, err
}
tw = &tableUpserter{ri: ri, fkTables: fkTables, updateCols: updateCols, conflictIndex: *conflictIndex, evaler: helper}
}
}
in := &insertNode{
n: n,
editNodeBase: en,
defaultExprs: defaultExprs,
insertCols: ri.insertCols,
insertColIDtoRowIndex: ri.insertColIDtoRowIndex,
tw: tw,
}
if err := in.checkHelper.init(p, tn, en.tableDesc); err != nil {
return nil, err
}
if err := in.run.initEditNode(&in.editNodeBase, rows, n.Returning, desiredTypes); err != nil {
return nil, err
}
return in, nil
}