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)
| 405 | // references to built-in types, when the identifer has already been |
| 406 | // parsed away from the input SQL syntax. |
| 407 | func 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 |