@@ -68,8 +68,8 @@ BindResult ExpressionBinder::TryBindLambdaOrJson(FunctionExpression &function, i
6868 json_bind_result.error .RawMessage ());
6969}
7070
71- BindResult ExpressionBinder::BindExpression (FunctionExpression &function, idx_t depth,
72- unique_ptr<ParsedExpression> &expr_ptr) {
71+ optional_ptr<CatalogEntry> ExpressionBinder::BindAndQualifyFunction (FunctionExpression &function, bool allow_throw) {
72+ D_ASSERT (! IsUnnestFunction (function. function_name ));
7373 // lookup the function in the catalog
7474 QueryErrorContext error_context (function.GetQueryLocation ());
7575 binder.BindSchemaOrCatalog (function.catalog , function.schema );
@@ -82,6 +82,9 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
8282 auto table_func =
8383 GetCatalogEntry (function.catalog , function.schema , table_function_lookup, OnEntryNotFound::RETURN_NULL);
8484 if (table_func) {
85+ if (!allow_throw) {
86+ return func;
87+ }
8588 throw BinderException (function,
8689 " Function \" %s\" is a table function but it was used as a scalar function. This "
8790 " function has to be called in a FROM clause (similar to a table)." ,
@@ -105,6 +108,9 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
105108 if (error.HasError ()) {
106109 // could not find the column - try to qualify the alias
107110 if (!QualifyColumnAlias (*colref)) {
111+ if (!allow_throw) {
112+ return func;
113+ }
108114 // no alias found either - throw
109115 error.Throw ();
110116 }
@@ -118,11 +124,19 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
118124 }
119125 // rebind the function
120126 if (!func) {
121- func =
122- GetCatalogEntry (function.catalog , function.schema , function_lookup, OnEntryNotFound::THROW_EXCEPTION);
127+ const auto on_entry_not_found =
128+ allow_throw ? OnEntryNotFound::THROW_EXCEPTION : OnEntryNotFound::RETURN_NULL;
129+ func = GetCatalogEntry (function.catalog , function.schema , function_lookup, on_entry_not_found);
123130 }
124131 }
125132
133+ return func;
134+ }
135+
136+ BindResult ExpressionBinder::BindExpression (FunctionExpression &function, idx_t depth,
137+ unique_ptr<ParsedExpression> &expr_ptr) {
138+ auto func = BindAndQualifyFunction (function, true );
139+
126140 if (func->type != CatalogType::AGGREGATE_FUNCTION_ENTRY &&
127141 (function.distinct || function.filter || !function.order_bys ->orders .empty ())) {
128142 throw InvalidInputException (" Function \" %s\" is a %s. \" DISTINCT\" , \" FILTER\" , and \" ORDER BY\" are only "
0 commit comments