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

Function GetTypeFromCastOrCollate

pkg/sql/parser/parse.go:436–450  ·  view source on GitHub ↗

GetTypeFromCastOrCollate returns the type of the given tree.Expr. The method assumes that the expression is either tree.CastExpr or tree.CollateExpr (which wraps the tree.CastExpr).

(expr tree.Expr)

Source from the content-addressed store, hash-verified

434// assumes that the expression is either tree.CastExpr or tree.CollateExpr
435// (which wraps the tree.CastExpr).
436func GetTypeFromCastOrCollate(expr tree.Expr) (tree.ResolvableTypeReference, error) {
437 // COLLATE clause has lower precedence than the cast, so if we have
438 // something like `1::STRING COLLATE en`, it'll be parsed as
439 // CollateExpr(CastExpr).
440 if collate, ok := expr.(*tree.CollateExpr); ok {
441 return types.MakeCollatedString(types.String, collate.Locale), nil
442 }
443
444 cast, ok := expr.(*tree.CastExpr)
445 if !ok {
446 return nil, errors.AssertionFailedf("expected a tree.CastExpr, but found %T", expr)
447 }
448
449 return cast.Type, nil
450}
451
452var errVarBitLengthNotPositive = pgerror.WithCandidateCode(
453 errors.New("length for type varbit must be at least 1"), pgcode.InvalidParameterValue)

Callers 1

Calls 1

MakeCollatedStringFunction · 0.92

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…