Add replace=True parameter to create_function for Python UDFs #459
eribertoczdev
started this conversation in
Ideas
Replies: 1 comment
-
|
fwiw, this matches what I see on Until import duckdb
def create_or_replace_udf(con, name, fn, parameters=None, return_type=None):
try:
con.remove_function(name)
except duckdb.InvalidInputException as e:
if "No function by the name" not in str(e):
raise
return con.create_function(name, fn, parameters, return_type)I tested that with an in-memory connection by registering |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Feature Request:
replaceparameter forcreate_functionMotivation
When developing with Python UDFs, updating an existing function requires two separate calls with a try/except pattern:
This is error-prone and verbose, especially when managing multiple UDFs in a bootstrap registration function. It also masks real errors since the bare
exceptsilently swallows any exception fromremove_function.Current Behavior
Calling
create_functionwith an existing name raises:Proposed Solution
Add a
replaceparameter tocreate_function:Or alternatively, a dedicated method (consistent with SQL's
CREATE OR REPLACEsemantics):The
replace=Trueapproach is preferred as it avoids adding a new method to the API surface and is consistent with how other parameters increate_functionwork.Additional Context
This pattern is especially common during development and in notebook environments where cells are re-run frequently. The SQL
CREATE OR REPLACE MACROalready supports this semantic — it would be natural to expose the same capability in the Python API.Beta Was this translation helpful? Give feedback.
All reactions