2

I have this raw mysql query, SELECT user_id FROM user WHERE email_address NOT REGEXP '[^@]+@[^@]+\.[^@]+', this filters all email addresses having invalid email addresses.

I will need an SQLAlchemy equivalent for this.

I have tried this query, User.query.filter(User.email_address.op('regexp')(r'[^@]+@[^@]+\.[^@]+')).all(), but it filters all the valid email addresses. I just need to know how to add the NOT in this query.

1
  • Did you try using sqlalchemy.not()? Commented Jul 29, 2017 at 17:01

1 Answer 1

2

try this:

User.query.filter(User.email_address.op('not regexp')(r'[^@]+@[^@]+\.[^@]+')).all()

Sign up to request clarification or add additional context in comments.

Comments

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.