本文整理匯總了Golang中github.com/cockroachdb/cockroach/pkg/sql/parser.TableName.TableName方法的典型用法代碼示例。如果您正苦於以下問題:Golang TableName.TableName方法的具體用法?Golang TableName.TableName怎麽用?Golang TableName.TableName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/pkg/sql/parser.TableName
的用法示例。
在下文中一共展示了TableName.TableName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: getDataSource
// getDataSource builds a planDataSource from a single data source clause
// (TableExpr) in a SelectClause.
func (p *planner) getDataSource(
src parser.TableExpr, hints *parser.IndexHints, scanVisibility scanVisibility,
) (planDataSource, error) {
switch t := src.(type) {
case *parser.NormalizableTableName:
// Usual case: a table.
tn, err := p.QualifyWithDatabase(t)
if err != nil {
return planDataSource{}, err
}
// Is this perhaps a name for a virtual table?
ds, foundVirtual, err := p.getVirtualDataSource(tn)
if err != nil {
return planDataSource{}, err
}
if foundVirtual {
return ds, nil
}
return p.getTableScanOrViewPlan(tn, hints, scanVisibility)
case *parser.Subquery:
return p.getSubqueryPlan(t.Select, nil)
case *parser.JoinTableExpr:
// Joins: two sources.
left, err := p.getDataSource(t.Left, nil, scanVisibility)
if err != nil {
return left, err
}
right, err := p.getDataSource(t.Right, nil, scanVisibility)
if err != nil {
return right, err
}
return p.makeJoin(t.Join, left, right, t.Cond)
case *parser.ParenTableExpr:
return p.getDataSource(t.Expr, hints, scanVisibility)
case *parser.AliasedTableExpr:
// Alias clause: source AS alias(cols...)
src, err := p.getDataSource(t.Expr, t.Hints, scanVisibility)
if err != nil {
return src, err
}
var tableAlias parser.TableName
if t.As.Alias != "" {
// If an alias was specified, use that.
tableAlias.TableName = parser.Name(t.As.Alias.Normalize())
src.info.sourceAliases = sourceAliases{
tableAlias: fillColumnRange(0, len(src.info.sourceColumns)-1),
}
}
colAlias := t.As.Cols
if len(colAlias) > 0 {
// Make a copy of the slice since we are about to modify the contents.
src.info.sourceColumns = append(ResultColumns(nil), src.info.sourceColumns...)
// The column aliases can only refer to explicit columns.
for colIdx, aliasIdx := 0, 0; aliasIdx < len(colAlias); colIdx++ {
if colIdx >= len(src.info.sourceColumns) {
var srcName string
if tableAlias.DatabaseName != "" {
srcName = tableAlias.String()
} else {
srcName = tableAlias.TableName.String()
}
return planDataSource{}, errors.Errorf(
"source %q has %d columns available but %d columns specified",
srcName, aliasIdx, len(colAlias))
}
if src.info.sourceColumns[colIdx].hidden {
continue
}
src.info.sourceColumns[colIdx].Name = string(colAlias[aliasIdx])
aliasIdx++
}
}
return src, nil
default:
return planDataSource{}, errors.Errorf("unsupported FROM type %T", src)
}
}