tediousjs / node-mssql

Microsoft SQL Server client for Node.js
https://tediousjs.github.io/node-mssql
MIT License
2.23k stars 466 forks source link

Allow array as inputs into string_split argument #1583

Closed mikewang333 closed 8 months ago

mikewang333 commented 10 months ago

Could we allow arrays to be passed in as inputs if they're being used in a string_split function? I know the documentation says the input should be a string, but it looks like mssql servers also handle array inputs here.

Example: Query is: select * from string_split(@param1, ',')

And we define input @param1 as [1, 2, 3]

Expected behaviour:

Output should be [1, 2, 3]

Actual behaviour:

Receives error: "Validation failed for parameter 'param1'. Invalid string."

Software versions

dhensby commented 10 months ago

I'm a bit unclear on this.

Firstly, the requested feature isn't really possible on two fronts:

  1. The query has no idea what the context of the parameter is, if can't know that it's being used in a string_split() function or just as a plain query parameter, so there's no way to allow array inputs in just one particular usecase.
  2. There is no way (that I know) to provide an "array" to an argument as a parameter. They'd need to go via a temp table, or some other structured data to then be referenced as a list of items.

Secondly, I don't see where in the documentation that it claims that an array could be used. This is explicitly a "string" splitting function and all the examples show that.