Skip to content

Support omitting named arguments in table UDFs#130

Open
achille-roussel wants to merge 1 commit into
duckdb:mainfrom
achille-roussel:named-arguments-default-values
Open

Support omitting named arguments in table UDFs#130
achille-roussel wants to merge 1 commit into
duckdb:mainfrom
achille-roussel:named-arguments-default-values

Conversation

@achille-roussel
Copy link
Copy Markdown

@achille-roussel achille-roussel commented Apr 5, 2026

Summary

  • When a named argument is omitted, duckdb_bind_get_named_parameter returns a value with DUCKDB_TYPE_INVALID. Previously this propagated through getValue() and surfaced as Binder Error: unsupported data type: INVALID.
  • Now, an omitted named argument inserts nil into the namedArgs map passed to BindArguments, allowing the user's bind function to detect the absence and apply its own default.
  • No API changes — existing code that requires all named arguments continues to work unchanged.

🤖 Generated with Claude Code

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>
@achille-roussel
Copy link
Copy Markdown
Author

Hello @mlafeldt, do you have any feedback on the change?

Copy link
Copy Markdown
Member

@mlafeldt mlafeldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM in general. See my comment on nil vs absent though.

Comment thread table_udf.go
if t == TYPE_INVALID {
// Argument was omitted; pass nil so the bind function can apply a default.
mapping.DestroyValue(&value)
namedArgs[name] = nil
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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]?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's open a PR to duckdb/duckdb introducing a duckdb_bind_has_named_parameter C API function. 👍

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mlafeldt mlafeldt added the feature / enhancement Code improvements or a new feature label Apr 21, 2026
@taniabogatsch taniabogatsch added the requires latest duckdb Relies on latest changes in duckdb main label May 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature / enhancement Code improvements or a new feature requires latest duckdb Relies on latest changes in duckdb main

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants