question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Op.like]: example from documentation throws SQL error

See original GitHub issue

What 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:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
papbcommented, Aug 23, 2019

After further investigation, it seems that LIKE ANY is supported in Postgres only, since the ARRAY datatype is itself PG only. What SQL query were you expecting instead? Are you sure this should work in MySQL?

I expected to get a list of Media where the image_title contains either ‘cat’ or ‘hat’

For this you can use Op.or, for example, I believe.

0reactions
ephyscommented, Apr 16, 2022

Closing with resolution that Op.any is a postgres specific feature that cannot be used in MySQL.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found