本文整理汇总了Golang中github.com/pingcap/tidb/ast.UnionStmt.GetResultFields方法的典型用法代码示例。如果您正苦于以下问题:Golang UnionStmt.GetResultFields方法的具体用法?Golang UnionStmt.GetResultFields怎么用?Golang UnionStmt.GetResultFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/pingcap/tidb/ast.UnionStmt
的用法示例。
在下文中一共展示了UnionStmt.GetResultFields方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: buildUnion
func (b *planBuilder) buildUnion(union *ast.UnionStmt) Plan {
sels := make([]Plan, len(union.SelectList.Selects))
for i, sel := range union.SelectList.Selects {
sels[i] = b.buildSelect(sel)
}
var p Plan
p = &Union{
Selects: sels,
}
unionFields := union.GetResultFields()
for _, sel := range sels {
for i, f := range sel.Fields() {
if i == len(unionFields) {
b.err = errors.New("The used SELECT statements have a different number of columns")
return nil
}
uField := unionFields[i]
/*
* The lengths of the columns in the UNION result take into account the values retrieved by all of the SELECT statements
* SELECT REPEAT('a',1) UNION SELECT REPEAT('b',10);
* +---------------+
* | REPEAT('a',1) |
* +---------------+
* | a |
* | bbbbbbbbbb |
* +---------------+
*/
if f.Column.Flen > uField.Column.Flen {
uField.Column.Flen = f.Column.Flen
}
// For select nul union select "abc", we should not convert "abc" to nil.
// And the result field type should be VARCHAR.
if uField.Column.Tp == 0 || uField.Column.Tp == mysql.TypeNull {
uField.Column.Tp = f.Column.Tp
}
}
addChild(p, sel)
}
for _, v := range unionFields {
v.Expr.SetType(&v.Column.FieldType)
}
p.SetFields(unionFields)
if union.Distinct {
p = b.buildDistinct(p)
}
if union.OrderBy != nil {
p = b.buildSort(p, union.OrderBy.Items)
}
if union.Limit != nil {
p = b.buildLimit(p, union.Limit)
}
return p
}