Alex
Alex

Reputation: 625

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?

Upvotes: 0

Views: 1078

Answers (1)

Andronicus
Andronicus

Reputation: 26066

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""")

Upvotes: 1

Related Questions