1

How could I go about utilizing the Postgres Prefix Plugin within django? Is there a way to just append an additional WHERE clause to the queries that django runs without going into raw SQL?

Maybe something like this?

Model.objects.filter(field1=2, field2__in=[1,2,3]).where("prefix @> '0123456789'")

1 Answer 1

2

Yes it is possible, this is the extra method on QuerySet. Something like this should do the trick:

 Model.objects.filter(...).extra(where=["prefix @> '0123456789'"])
Sign up to request clarification or add additional context in comments.

2 Comments

My concern is that it will be deprecated soon according to their docs.
As far as I know, there is no fixed deprecation plan yet so it will be there for several versions and at the time they remove it, there will maybe be another way to do that. Right now, the only other way I see to achieve your goal is to use raw sql queries (docs.djangoproject.com/en/1.8/topics/db/sql/…) but you will have to write the whole query yourself.

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.