Support omitting named arguments in table UDFs#130
Conversation
When a named argument is omitted at call time, duckdb_bind_get_named_parameter returns a value with DUCKDB_TYPE_INVALID. The previous code forwarded this to getValue(), which hit the unsupported-type path and surfaced: Binder Error: unsupported data type: INVALID Now, an omitted named argument silently inserts nil into the namedArgs map passed to BindArguments, letting the user's bind function detect and handle the absence (e.g. apply a default value). Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
Hello @mlafeldt, do you have any feedback on the change? |
mlafeldt
left a comment
There was a problem hiding this comment.
LGTM in general. See my comment on nil vs absent though.
| if t == TYPE_INVALID { | ||
| // Argument was omitted; pass nil so the bind function can apply a default. | ||
| mapping.DestroyValue(&value) | ||
| namedArgs[name] = nil |
There was a problem hiding this comment.
I'm worried about conflating "omitted" with "type resolution failure" here. TYPE_INVALID is also DuckDB's sentinel for unresolved/unknown parameter types.
Why not leave the key absent and let users do _, ok := namedArgs[name]?
There was a problem hiding this comment.
I agree, from what I can tell this is a limitation in the C API (duckdb/duckdb) side. We need to expose a duckdb_bind_has_named_parameter or similar there to actually check if the parameter was provided or not, which we can then use here.
I am hesitant about patching this up in the driver level.
There was a problem hiding this comment.
Why not leave the key absent and let users do _, ok := namedArgs[name]?
I did it this way because in all my use cases, the behavior for the argument being omitted was the same as if it had bee set to NULL.
I don't have enough context to know which approach to take, but let me know what you want and I can make the fix.
There was a problem hiding this comment.
Let's open a PR to duckdb/duckdb introducing a duckdb_bind_has_named_parameter C API function. 👍
Summary
duckdb_bind_get_named_parameterreturns a value withDUCKDB_TYPE_INVALID. Previously this propagated throughgetValue()and surfaced asBinder Error: unsupported data type: INVALID.nilinto thenamedArgsmap passed toBindArguments, allowing the user's bind function to detect the absence and apply its own default.🤖 Generated with Claude Code