UPDATE with rawSQL plugin and IN operator

I need to update a column in the table_name using the rawSQL plugin.
Is it possible to use the ‘IN’ operator using such a code:

        var paramsArray = [x,y];
	var sqlString = 'UPDATE table_name SET field_1 = 1 WHERE field_y IN ?';
		
	var done = plugins.rawSQL.executeSQL('server_name','table_name',sqlString,paramsArray);

Thanks in advance.

Hi,

SQL requires a placeholder per argument you pass so the example code you gave will error.
You can use an IN statement and still use a prepared statement like so:

var paramsArray = [x,y];
var sqlString = "UPDATE table_name SET field_1 = 1 WHERE field_y IN (" + paramsArray.map(function() {return "?"}).join(",") + ")";
var done = plugins.rawSQL.executeSQL('server_name','table_name',sqlString,paramsArray);

This will generate the amount of placeholders for the values in your parameter array.

Hope this helps.

I guessed the problem was referred to the parameters but I didn’t get how to resolve!
Thank you very much!