本文整理匯總了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
}