I have a mysql query like this: 'SELECT ? FROM tablename'
with an args array like this: ['id']
.
When I call db.query(sql, args)
the result is an array with ['id', 'id', 'id']
for every row in the database table instead of having the values from the database in it [1,2,3]
.
If the column names are included in the sql string it works just fine. I really dont know why this happends. Is there someone else having issues like this and has a solution for it?
Asked
Active
Viewed 1,104 times
-1

Kilian
- 51
- 6
-
I dont know much about node but I doubt that you can parametrize column or table names – Mihai Sep 19 '19 at 19:25
-
1@Mihai `node-mysql` is actually nice in that you can. – tadman Sep 19 '19 at 19:29
1 Answers
1
You can parameterize column names with the ??
placeholder as per the documentation:
db.query('SELECT ?? FROM tablename', [ [ 'id', 'id', ... ] ]);

tadman
- 208,517
- 23
- 234
- 262
-
1
-
1@Kilian - if this solved your issue consider indicating it as an accepted answer, good luck with your project! – dusthaines Sep 20 '19 at 01:37