MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / GetTypeReferenceFromName

Function GetTypeReferenceFromName

pkg/sql/parser/parse.go:407–419  ·  view source on GitHub ↗

GetTypeReferenceFromName turns a type name into a type reference. This supports only “simple” (single-identifier) references to built-in types, when the identifer has already been parsed away from the input SQL syntax.

(typeName tree.Name)

Source from the content-addressed store, hash-verified

405// references to built-in types, when the identifer has already been
406// parsed away from the input SQL syntax.
407func GetTypeReferenceFromName(typeName tree.Name) (tree.ResolvableTypeReference, error) {
408 expr, err := ParseExpr(fmt.Sprintf("1::%s", typeName.String()))
409 if err != nil {
410 return nil, err
411 }
412
413 cast, ok := expr.(*tree.CastExpr)
414 if !ok {
415 return nil, errors.AssertionFailedf("expected a tree.CastExpr, but found %T", expr)
416 }
417
418 return cast.Type, nil
419}
420
421// GetTypeFromValidSQLSyntax retrieves a type from its SQL syntax. The caller is
422// responsible for guaranteeing that the type expression is valid

Callers

nothing calls this directly

Calls 2

ParseExprFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…