-
Notifications
You must be signed in to change notification settings - Fork 77
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
UDF support #49
Comments
cc: @jonnickerson |
This is already possible since 0.5.1! I opened a PR with an example |
Reopening this as an easier solution can be made here |
I think this should be a separate issue with more details (the proposed API) |
Proposed API: # Load the extension and connect to the database
%load_ext sql
%sql postgresql://username:password@localhost:5432/mydatabase
# Define a function that takes in a value and returns its square
def my_square_function(x):
return x * x
# Use the func module to define the UDF as a SQL expression
from sqlalchemy import func
square_udf = func.my_square_function(column)
# Use the UDF in a SELECT statement
result = %sql SELECT *, :square_udf AS squared_value FROM mytable
# Print the result set
print(result) We might want to even create a tighter integration to the func part, maybe something like: # Define the UDF as a SQL expression
%sql --udf square_udf=my_square_function
# And then consume it
%sql SELECT *, :square_udf AS squared_value FROM mytable In the second snippet we take the extra step to wrap |
this is highly db dependent, I think we should close it |
The question I have is how many users actually have UDFs, I know it's pretty common with DWHs, and is supported by most if not all of them (At least snowflake, bigquery, redshift). |
ok, then let's start with a single one, the one that has the most users. |
each db has its own mechanism for defining UDFs so it'll take a lot of effort to unify them in a single API |
Currently the package doesn't support it.
We should add a feature to accept it and execute it via the engine.
The text was updated successfully, but these errors were encountered: