0

Looking for any example of making SOUNDEX queries on MySQL from SQLAlchemy, if possible at all. Any alternatives?

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
martincho
  • 4,517
  • 7
  • 32
  • 42

1 Answers1

1

If all you need is to use the SOUNDEX() function, then just use func to generate the function expression:

session.query(func.soundex(MyModel.some_str))

If on the other hand you need the SOUNDS LIKE operator, you can use op():

session.query(MyModel).\
    filter(MyModel.some_str.op('SOUNDS LIKE')('Supercalifragilisticexpialidocious'))

which is equivalent to

session.query(MyModel).\
    filter(func.soundex(MyModel.some_str) ==
           func.soundex('Supercalifragilisticexpialidocious'))
Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127