Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling SQL functions from Blaze

In particular I would like to call the Postgres levenshtein function. I would like to write the blaze query to return words similar to the word 'similar', ie the equivalent of:

select word from wordtable where levenshtein(word, 'similar') < 3;

In Blaze this should look something like

db.wordtable.word[levenshtein(db.wordtable.word, 'similar') < 3]

but levenshtein is not defined in any module I am importing on the python side. Where/how do I get a levenshtein definition for use in Blaze expressions on the Python side?


I have found the sqlalchemy.sql.func package which provides Python handles for SQL functions for use with SqlAlchemy, but these do not work in Blaze expressions. Is there an equivalent Blaze package, or how can I use sqlalchemy.sql.func.levenshtein inside a Blaze expression?

like image 730
Daniel Mahler Avatar asked Nov 18 '16 07:11

Daniel Mahler


1 Answers

PyPi is your friend. Searching there finds the python-Levenshtein package. If you're on windows and want a precompiled version, use Christoph Gohlke's wheel (his builds are safe, reliable, and correct; numpy builds use the MKL libraries, so they're fast too!).

like image 131
cco Avatar answered Oct 12 '22 07:10

cco