如何使用ipythonsql(https://github.com/catherinedevlin/ipython-sql)在Jupyter/iPython中创建自定义SQLite UDF 还是另一个ipythonsql魔法库
我正试着做这样的事
%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])
有什么想法吗
目前没有回答
相关问题 更多 >
编程相关推荐