本文整理匯總了Golang中github.com/cockroachdb/cockroach/sql/parser.QualifiedName.NormalizeColumnName方法的典型用法代碼示例。如果您正苦於以下問題:Golang QualifiedName.NormalizeColumnName方法的具體用法?Golang QualifiedName.NormalizeColumnName怎麽用?Golang QualifiedName.NormalizeColumnName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cockroachdb/cockroach/sql/parser.QualifiedName
的用法示例。
在下文中一共展示了QualifiedName.NormalizeColumnName方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: findColumn
// findColumn looks up the column described by a QualifiedName. The qname will be normalized.
func (qt qvalResolver) findColumn(qname *parser.QualifiedName) (columnRef, error) {
ref := columnRef{colIdx: invalidColIdx}
if err := qname.NormalizeColumnName(); err != nil {
return ref, err
}
// We can't resolve stars to a single column.
if qname.IsStar() {
err := fmt.Errorf("qualified name \"%s\" not found", qname)
return ref, err
}
// TODO(radu): when we support multiple FROMs, we will find the node with the correct alias; if
// no alias is given, we will search for the column in all FROMs and make sure there is only
// one. For now we just check that the name matches (if given).
if qname.Base == "" {
qname.Base = parser.Name(qt.table.alias)
}
if equalName(qt.table.alias, string(qname.Base)) {
colName := qname.Column()
for idx, col := range qt.table.columns {
if equalName(col.Name, colName) {
ref.table = qt.table
ref.colIdx = idx
return ref, nil
}
}
}
err := fmt.Errorf("qualified name \"%s\" not found", qname)
return ref, err
}
示例2: findColumn
// findColumn looks up the column described by a QualifiedName. The qname will be normalized.
func (qt qvalResolver) findColumn(qname *parser.QualifiedName) (columnRef, error) {
ref := columnRef{colIdx: invalidColIdx}
if err := qname.NormalizeColumnName(); err != nil {
return ref, err
}
// We can't resolve stars to a single column.
if qname.IsStar() {
err := fmt.Errorf("qualified name \"%s\" not found", qname)
return ref, err
}
colName := sqlbase.NormalizeName(qname.Column())
for _, table := range qt.tables {
if qname.Base == "" || sqlbase.EqualName(table.alias, string(qname.Base)) {
for idx, col := range table.columns {
if sqlbase.NormalizeName(col.Name) == colName {
if ref.colIdx != invalidColIdx {
return ref, fmt.Errorf("column reference \"%s\" is ambiguous", qname)
}
ref.table = table
ref.colIdx = idx
}
}
}
}
if ref.colIdx == invalidColIdx {
return ref, fmt.Errorf("qualified name \"%s\" not found", qname)
}
return ref, nil
}