Eval implements the TypedExpr interface.
(ctx *EvalContext)
| 3157 | |
| 3158 | // Eval implements the TypedExpr interface. |
| 3159 | func (expr *CaseExpr) Eval(ctx *EvalContext) (Datum, error) { |
| 3160 | if expr.Expr != nil { |
| 3161 | // CASE <val> WHEN <expr> THEN ... |
| 3162 | // |
| 3163 | // For each "when" expression we compare for equality to <val>. |
| 3164 | val, err := expr.Expr.(TypedExpr).Eval(ctx) |
| 3165 | if err != nil { |
| 3166 | return nil, err |
| 3167 | } |
| 3168 | |
| 3169 | for _, when := range expr.Whens { |
| 3170 | arg, err := when.Cond.(TypedExpr).Eval(ctx) |
| 3171 | if err != nil { |
| 3172 | return nil, err |
| 3173 | } |
| 3174 | d, err := evalComparison(ctx, EQ, val, arg) |
| 3175 | if err != nil { |
| 3176 | return nil, err |
| 3177 | } |
| 3178 | if v, err := GetBool(d); err != nil { |
| 3179 | return nil, err |
| 3180 | } else if v { |
| 3181 | return when.Val.(TypedExpr).Eval(ctx) |
| 3182 | } |
| 3183 | } |
| 3184 | } else { |
| 3185 | // CASE WHEN <bool-expr> THEN ... |
| 3186 | for _, when := range expr.Whens { |
| 3187 | d, err := when.Cond.(TypedExpr).Eval(ctx) |
| 3188 | if err != nil { |
| 3189 | return nil, err |
| 3190 | } |
| 3191 | if v, err := GetBool(d); err != nil { |
| 3192 | return nil, err |
| 3193 | } else if v { |
| 3194 | return when.Val.(TypedExpr).Eval(ctx) |
| 3195 | } |
| 3196 | } |
| 3197 | } |
| 3198 | |
| 3199 | if expr.Else != nil { |
| 3200 | return expr.Else.(TypedExpr).Eval(ctx) |
| 3201 | } |
| 3202 | return DNull, nil |
| 3203 | } |
| 3204 | |
| 3205 | // pgSignatureRegexp matches a Postgres function type signature, capturing the |
| 3206 | // name of the function into group 1. |
nothing calls this directly
no test coverage detected