0

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?

1 Answer 1

1

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""")
Sign up to request clarification or add additional context in comments.

1 Comment

Additionally, I need to add one more point to this answer, need to create the following extension first to work this these similarity queries. CREATE EXTENSION IF NOT EXISTS pg_trgm;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.