MCPcopy Create free account
hub / github.com/auxten/postgresql-parser / Eval

Method Eval

pkg/sql/sem/tree/eval.go:4498–4525  ·  view source on GitHub ↗

Eval implements the TypedExpr interface.

(ctx *EvalContext)

Source from the content-addressed store, hash-verified

4496
4497// Eval implements the TypedExpr interface.
4498func (t *Placeholder) Eval(ctx *EvalContext) (Datum, error) {
4499 if !ctx.HasPlaceholders() {
4500 // While preparing a query, there will be no available placeholders. A
4501 // placeholder evaluates to itself at this point.
4502 return t, nil
4503 }
4504 e, ok := ctx.Placeholders.Value(t.Idx)
4505 if !ok {
4506 return nil, makeNoValueProvidedForPlaceholderErr(t.Idx)
4507 }
4508 // Placeholder expressions cannot contain other placeholders, so we do
4509 // not need to recurse.
4510 typ := ctx.Placeholders.Types[t.Idx]
4511 if typ == nil {
4512 // All placeholders should be typed at this point.
4513 return nil, errors.AssertionFailedf("missing type for placeholder %s", t)
4514 }
4515 if !e.ResolvedType().Equivalent(typ) {
4516 // This happens when we overrode the placeholder's type during type
4517 // checking, since the placeholder's type hint didn't match the desired
4518 // type for the placeholder. In this case, we cast the expression to
4519 // the desired type.
4520 // TODO(jordan): introduce a restriction on what casts are allowed here.
4521 cast := &CastExpr{Expr: e, Type: typ}
4522 return cast.Eval(ctx)
4523 }
4524 return e.Eval(ctx)
4525}
4526
4527func evalComparison(ctx *EvalContext, op ComparisonOperator, left, right Datum) (Datum, error) {
4528 if left == DNull || right == DNull {

Callers

nothing calls this directly

Calls 7

EvalMethod · 0.95
HasPlaceholdersMethod · 0.80
EquivalentMethod · 0.80
ResolvedTypeMethod · 0.65
EvalMethod · 0.65
ValueMethod · 0.45

Tested by

no test coverage detected