1#include "duckdb/parser/expression/cast_expression.hpp"
2#include "duckdb/planner/expression/bound_cast_expression.hpp"
3#include "duckdb/planner/expression/bound_parameter_expression.hpp"
4#include "duckdb/planner/expression_binder.hpp"
5
6using namespace duckdb;
7using namespace std;
8
9BindResult ExpressionBinder::BindExpression(CastExpression &expr, idx_t depth) {
10 // first try to bind the child of the cast expression
11 string error = Bind(&expr.child, depth);
12 if (!error.empty()) {
13 return BindResult(error);
14 }
15 // the children have been successfully resolved
16 auto &child = (BoundExpression &)*expr.child;
17 if (child.expr->type == ExpressionType::VALUE_PARAMETER) {
18 auto &parameter = (BoundParameterExpression &)*child.expr;
19 // parameter: move types into the parameter expression itself
20 parameter.return_type = GetInternalType(expr.cast_type);
21 parameter.sql_type = expr.cast_type;
22 } else {
23 // otherwise add a cast to the target type
24 child.expr = BoundCastExpression::AddCastToType(move(child.expr), child.sql_type, expr.cast_type);
25 }
26 return BindResult(move(child.expr), expr.cast_type);
27}
28