[英]How do I create a custom Sqlite UDF while using ipython-sql in a Jupyter Notebook?
我将如何使用 ipython-sql ( https://github.com/catherinedevlin/ipython-sql ) 或其他 iPython SQL 魔术库在 Jupyter/iPython 中创建自定义 SQLite UDF?
我正在尝试做这样的事情......
%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
使用 sqlite3 Python 库时,它将是...
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])
有任何想法吗??
%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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.