How would I go about creating a custom SQLite UDF in Jupyter/iPython with ipython-sql ( https://github.com/catherinedevlin/ipython-sql ) or another iPython SQL magic library?
I'm trying to do something like this...
%load_ext sql
%sql sqlite:///
%sql create table example(col text)
%sql insert into example (col) values ('stuff')
to_upper = lambda x: x.upper()
%sql select upper(col) from example
When using the sqlite3 Python library it would be...
from sqlalchemy import create_engine
conn = create_engine('sqlite://')
conn.execute('create table example(col text)')
conn.execute("insert into example values ('stuff')")
to_upper = lambda x: x.upper()
connection = conn.raw_connection()
connection.create_function('to_upper', 1, to_upper)
print(conn.execute("select to_upper(col) col from example").fetchall()[0][0])
Any ideas??
%load_ext sql
%sql sqlite:///
%sql create table example(col text)
%sql insert into example (col) values ('stuff')
to_upper = lambda x: x.upper()
x=%sql -l
connection=x['sqlite://'].session.connection.connection
connection.create_function('to_upper', 1, to_upper)
%sql select upper(col) from example
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.