[Op.like]: example from documentation throws SQL error
See original GitHub issueWhat are you doing?
Using the following example from the documentation throws a SQL error on MySQL
Media.findAll({
where: {
image_title: {
[Op.like]: { [Op.any]: ['cat', 'hat']}
}
}
})
To Reproduce Steps to reproduce the behavior:
Perform the above query - generated SQL in Node/Express is as follows:
`Executing (default): SELECT `id`, `story_title`, `image_title`, `original_filename`,
`created_at` AS `createdAt`, `updated_at` AS `updatedAt` FROM `media` AS `media`
WHERE `media`.`image_title` LIKE ANY ('cat', 'hat');`
What do you expect to happen?
I expected to get a list of Media where the image_title contains either ‘cat’ or ‘hat’
What is actually happening?
I get a console error in Chrome that reads:
“You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘(‘cat’, ‘hat’)’ at line 1”
And no images.
Environment
Dialect:
- [x ] mysql
- postgres
- sqlite
- mssql
- any Dialect ** mysql2** version: 1.6.5 Database version: 8.0.13 Sequelize version: 5.8.5 Node Version: 11.1.0 OS: Mac OSX 10.14.4 If TypeScript related: TypeScript version: N/A Tested with latest release:
- No
- [x ] Yes, specify that version: 5.8.6
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
[Op.like]: example from Sequelize documentation throws SQL ...
What I'm trying to do is pass an array of strings into a query and return all images where the image_title contains any...
Read more >Common SQL syntax errors and how to resolve them
In this article, we are going to describe some of the most common SQL syntax errors, and explains how you can resolve these...
Read more >Database Engine events and errors - SQL Server
Consult this MSSQL error code list to find explanations for error messages for SQL Server database engine events.
Read more >SQL error messages and exceptions - Oracle Help Center
The following tables list SQLStates for exceptions. ... 01003, Null values were eliminated from the argument of a column function.
Read more >Model Querying - Basics - Sequelize
Important notice: to perform production-ready queries with ... Just like Sequelize inferred the Op.eq operator in the first example, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
After further investigation, it seems that
LIKE ANY
is supported in Postgres only, since theARRAY
datatype is itself PG only. What SQL query were you expecting instead? Are you sure this should work in MySQL?For this you can use
Op.or
, for example, I believe.Closing with resolution that
Op.any
is a postgres specific feature that cannot be used in MySQL.