# Cannot pass param in sql command

**URL:** <https://discuss.elastic.co/t/cannot-pass-param-in-sql-command/321398>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-sql\
**Created:** [December 16, 2022, 10:32am UTC](https://discuss.elastic.co/t/cannot-pass-param-in-sql-command/321398 "2022-12-16T10:32:55Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![thanhdinh98](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thanhdinh98/32/114806_2.png) [@thanhdinh98](https://discuss.elastic.co/u/thanhdinh98)\
**Post date:** [December 16, 2022, 10:32am UTC](https://discuss.elastic.co/t/cannot-pass-param-in-sql-command/321398/1 "2022-12-16T10:32:55Z")

</div>

Hi everyone,  
I just face a problem in passing a param value in SQL command,  
The request is something like this

```auto
{
  "query": "select * from index where field in (?)",
  "params": [
    [
      "value1",
      "value2"
    ]
  ]
}

```

And I get this error

```auto
{
  "error": {
    "root_cause": [
      {
        "type": "x_content_parse_exception",
        "reason": "[1:108] Failed to parse object: unexpected token [START_ARRAY] found"
      }
    ],
    "type": "x_content_parse_exception",
    "reason": "[1:108] [sql/query] failed to parse field [params]",
    "caused_by": {
      "type": "x_content_parse_exception",
      "reason": "[1:108] Failed to parse object: unexpected token [START_ARRAY] found"
    }
  },
  "status": 400
}

```

Please let me know what's the thing I missed in this request and how can I correct this.  
Thank you in advance.

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [December 16, 2022, 11:17am UTC](https://discuss.elastic.co/t/cannot-pass-param-in-sql-command/321398/2 "2022-12-16T11:17:02Z")

</div>

You had extra brackets in there. Try this.

> [@thanhdinh98](#):
>
> ```auto
> {
> "query": "select * from index where field in (?)",
> "params": [
> "value1",
> "value2"
> ]
> }
> 
> ```

---

<div class="post-metadata">

**Author:** ![thanhdinh98](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thanhdinh98/32/114806_2.png) [@thanhdinh98](https://discuss.elastic.co/u/thanhdinh98)\
**Post date:** [December 16, 2022, 12:07pm UTC](https://discuss.elastic.co/t/cannot-pass-param-in-sql-command/321398/3 "2022-12-16T12:07:52Z")

</div>

HI @aaron-nimocks,  
Thanks for your comment, it works, but seems like it just takes the first value of the array and uses it in SQL command,  
I just received just 1 record from the request instead of a list of records by the values I passed in my select statement,  
I'm thinking about the solution that I need to generate the question mark placeholders based on the number of values I'm going to pass,  
it would be convenient if I could pass a list of values with an array for fetching a list of records with IN command in SQL,  
By the way, thank you guys for this great project,

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 13, 2023, 12:08pm UTC](https://discuss.elastic.co/t/cannot-pass-param-in-sql-command/321398/4 "2023-01-13T12:08:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
