| 1 | #include "duckdb/planner/expression_binder/having_binder.hpp" |
| 2 | |
| 3 | #include "duckdb/parser/expression/columnref_expression.hpp" |
| 4 | #include "duckdb/planner/binder.hpp" |
| 5 | #include "duckdb/planner/expression_binder/aggregate_binder.hpp" |
| 6 | #include "duckdb/common/string_util.hpp" |
| 7 | |
| 8 | using namespace duckdb; |
| 9 | using namespace std; |
| 10 | |
| 11 | HavingBinder::HavingBinder(Binder &binder, ClientContext &context, BoundSelectNode &node, BoundGroupInformation &info) |
| 12 | : SelectBinder(binder, context, node, info) { |
| 13 | target_type = SQLType(SQLTypeId::BOOLEAN); |
| 14 | } |
| 15 | |
| 16 | BindResult HavingBinder::BindExpression(ParsedExpression &expr, idx_t depth, bool root_expression) { |
| 17 | // check if the expression binds to one of the groups |
| 18 | auto group_index = TryBindGroup(expr, depth); |
| 19 | if (group_index != INVALID_INDEX) { |
| 20 | return BindGroup(expr, depth, group_index); |
| 21 | } |
| 22 | switch (expr.expression_class) { |
| 23 | case ExpressionClass::WINDOW: |
| 24 | return BindResult("HAVING clause cannot contain window functions!" ); |
| 25 | case ExpressionClass::COLUMN_REF: |
| 26 | return BindResult( |
| 27 | StringUtil::Format("column %s must appear in the GROUP BY clause or be used in an aggregate function" , |
| 28 | expr.ToString().c_str())); |
| 29 | default: |
| 30 | return ExpressionBinder::BindExpression(expr, depth); |
| 31 | } |
| 32 | } |
| 33 | |