【发布时间】:2019-07-03 13:46:50
【问题描述】:
我将如何使用 ipython-sql (https://github.com/catherinedevlin/ipython-sql) 在 Jupyter/iPython 中创建自定义 SQLite UDF 还是其他 iPython SQL 魔术库?
我正在尝试做这样的事情......
%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])
有什么想法吗??
【问题讨论】:
标签: python sql sqlite jupyter-notebook jupyter