-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for DuckDB Python Function API #1008
Comments
this works using a native connection! In [1]: import duckdb
...:
...: %load_ext sql
...: conn = duckdb.connect()
In [2]: def two(col_name: int) -> int:
...: return 2
...:
...: conn.create_function('two', two) # note that I'm calling create_function on the connection object!
Out[2]: <duckdb.duckdb.DuckDBPyConnection at 0x14bd553b0>
In [3]: %sql conn --alias duckdb
In [4]: %%sql
...: SELECT two(2);
...:
...:
Running query in 'duckdb'
Out[4]:
+--------+
| two(2) |
+--------+
| 2 |
+--------+ the main issue is that, by default, our documentation shows connecting to DuckDB via duckdb-engine, which uses sqlalchemy. we did this to keep backward compatibility with ipython-SQL. the problem is that using duckdb-native APIs through sqlalchemy is a bit tricky (we've encountered issues like this before), so we ended up writing logic to support native connections. native connections work pretty much the same as sqlalchemy ones, but the latter has been battle-tested over the years thanks to ipython-sql, so let me know if you encounter issues with native connections |
Is that the same issue as this PIVOT example (taken from https://duckdb.org/docs/sql/statements/pivot.html) not working?
When running the pivot code it shows an empty table (but if you use the Python interface it works):
|
I think the pivot problem is the same described here |
I'm trying to add a custom Python function to duckdb.
This is a silly example, but it shows an example.
I can use duckdb from the Python API and it works:
>>> duckdb.sql('SELECT two(2);') ┌────────┐ │ two(2) │ │ int64 │ ├────────┤ │ 2 │ └────────┘
However, the
%%sql
magic fails:It gives the following error:
The text was updated successfully, but these errors were encountered: