sidorares / sidorares/node-mysql2

Where in list prepared statement only returns first of list

Open
#1,291 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
4.4k
Forks
680
Avg merge
9h 7m
Merged PRs (30d)
59

Description

I have the following code. req.query.tags is a string of ids seperated by a comma, e.g. 1,2,3.

const query =
    'SELECT DISTINCT images.* FROM images LEFT JOIN images_has_tags ON image_id = images.id WHERE tag_id IN (?)';
const [rows] = await conn.query(query, [req.query.tags]);

This returns only one row, this row matches the first item in the list.
(If req.query.tags is 1,2,3, the query equals ...WHERE tag_id = 1)

Whereas

const query =
    'SELECT DISTINCT images.* FROM images LEFT JOIN images_has_tags ON image_id = images.id WHERE tag_id IN (1,2,3)';
const [rows] = await conn.query(query);

works fine.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the conn.query call shown in the report and trace how its parameter array is handled for the IN (?) placeholder. Reproduce the behavior with tags=1,2,3 and compare it with the working literal query. Done means the intended handling is clarified through a tested driver behavior or documented usage.

Written by the indexing model from the issue text.

Assessment

Tech stack
mysql, nodejs, typescript
Domain
database
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.