简体   繁体   中英

Sqlalchemy Fuzzystrmatch with Postgres extension

I am using the Postgres extension fuzzystrmatch . I want to replicate this (query) to the sqlalchemy ORM.

Example

SELECT * FROM mymodel WHERE soundex(denomination, 'PHONE') > 0.4;

That the match limit can be changed.

In sqlalchemy I am doing like this, but it does not work:

MyModel.query.filter(func.soundex(MyModel.denomination) == func.soundex('PHONE') > 0.4).all()

Any ideas?

You can execute it as a raw sql:

with engine.connect() as con:
    rs = con.execute("""SELECT * FROM mymodel WHERE SIMILARITY(denomination, 'PHONE') > 0.4""")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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