Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If column contains '+' in value, LIKE query does not work #12052

Closed
2 of 7 tasks
Awatatah opened this issue Apr 1, 2020 · 1 comment
Closed
2 of 7 tasks

If column contains '+' in value, LIKE query does not work #12052

Awatatah opened this issue Apr 1, 2020 · 1 comment
Labels

Comments

@Awatatah
Copy link

Awatatah commented Apr 1, 2020

#11727 Issue Description
LIKE query where column contains + returns 0 results

What are you doing?

With the below LIKE query on customer column email where email contains +

const Op = Sequelize.Op
let data: any[]
await Customer.findAll({
  where: {
    [Op.and]: [
      lastName: 'test',
      email: {
        [Op.iLike]: '%some+email+test@gmail.com%'
      }
    ]
  }
}).then((results: any) => {
  if (results.length > 0) {
    data = results
  }
})

What do you expect to happen?

Should result in 1 or more in data array

[
  {
    lastName: 'test',
    email: 'some+email+test@gmail.com'
  }
]

What is actually happening?

data is empty

[]

If I set the email query to [Op.iLike]: '%some%', then I get results.

[
  {
    lastName: 'test',
    email: 'some+email+test@gmail.com'
  }
]

Additional context

Environment

  • Sequelize version: 5.21.5
  • Node.js version: 12.10.0
  • Operating System: MacOS Catalina 10.15.4 (19E266)
  • TypeScript version: 3.7.5

Issue Template Checklist

How does this problem relate to dialects?

  • I think this problem happens regardless of the dialect.
  • I think this problem happens only for the following dialect(s): Postgres
  • I don't know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX

Would you be willing to resolve this issue by submitting a Pull Request?

  • Yes, I have the time and I know how to start.
  • Yes, I have the time but I don't know how to start, I would need guidance.
  • No, I don't have the time, although I believe I could do it if I had the time...
  • No, I don't have the time and I wouldn't even know how to start.
@Awatatah Awatatah changed the title If column contains '+' in value, query does not work If column contains '+' in value, LIKE query does not work Apr 1, 2020
@sushantdhiman
Copy link
Contributor

Yes, you want to escpace + as it is valid pattern matching operator https://www.postgresql.org/docs/9.6/functions-matching.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants