thirumalairaj
thirumalairaj

Reputation: 37

how to use mysql regexp in django1.4

Is it possible django 1.4

SELECT * FROM table WHERE columname regexp 'a|z|f'

I tried multiple filter with 'or' operator

Upvotes: 0

Views: 108

Answers (1)

cms_mgr
cms_mgr

Reputation: 2017

You can perform any SQL query using Django just by using custom SQL. Your example would be something like:

for i in Item.objects.raw("SELECT * FROM table WHERE columname regexp 'a|z|f'")

But you need to be careful with these because changing your database engine in future might lead to these queries breaking if the new engine uses a different syntax or doesn't support some of the feature's you're using.

Using the Django ORM itself you'll need something like:

for i in Item.objects.filter(columname__regex=r'a|z|f')

Upvotes: 1

Related Questions