NB:. This does not tell you how to do exactly what you want, but gives an explanation of why this does not work, and a possible next step to get this to work with SQLite.
The problem you are facing is that it is very difficult to efficiently execute arbitrary Python code for an arbitrary SQL database.
Blaze takes user code and translates it into SQL as much as possible using SQLAlchemy, which I think has no way to do this.
Since almost every database has a different way of working with user-defined functions (UDF), quite a lot of work is on creating an API that allows the following:
- User to define function in Python
- Turn this pure Python function into a database-specific UDF.
However, the Python interface for SQLite has a way to register Python functions that can be executed in an SQL statement:
https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.create_function
There is currently no way to express UDF using Blaze using the SQL backend, although this can be implemented as a new type of expression that allows the user to register a function through the base db API database.
source share