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

Pass an array as parameter #70

Open
wsporto opened this issue Aug 29, 2020 · 2 comments
Open

Pass an array as parameter #70

wsporto opened this issue Aug 29, 2020 · 2 comments

Comments

@wsporto
Copy link

wsporto commented Aug 29, 2020

Hello,

It is possible to pass an array as parameter?
The query bellow returns the error: Error: Operand should contain 1 column(s).

const ids = [1, 2, 3];
return client.query('SELECT * FROM mytable WHERE id in (?)', [ids]);
@stLmpp
Copy link

stLmpp commented Aug 30, 2020

Try it without the parentheses

const ids = [1, 2, 3];
return client.query('SELECT * FROM mytable WHERE id in ?', [ids]);

@wsporto
Copy link
Author

wsporto commented Aug 30, 2020

Thanks for your feedback.

Without the parenthesis works, but I have some problems:

  1. The query SELECT * FROM mytable WHERE id in ? is not a valid SQL according the MySQL grammar.
  2. I can’t have a query like that: SELECT * FROM mytable WHERE id in (99, 100, ?)

I am using this library in my project (typesql) where I parse the query following the MySQL grammar.

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

No branches or pull requests

2 participants