简体   繁体   English

如何在SQLAlchemy中使用MySQL SOUNDEX函数

[英]How to use MySQL SOUNDEX function with SQLAlchemy

Looking for any example of making SOUNDEX queries on MySQL from SQLAlchemy, if possible at all. 如果可能的话,寻找从SQLAlchemy在MySQL上进行SOUNDEX查询的任何示例。 Any alternatives? 有其他选择吗?

If all you need is to use the SOUNDEX() function, then just use func to generate the function expression: 如果您只需要使用SOUNDEX()函数,则只需使用func生成函数表达式:

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

If on the other hand you need the SOUNDS LIKE operator, you can use op() : 另一方面,如果您需要SOUNDS LIKE运算符,则可以使用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'))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM