# Formatting checkbox input for sql where clause

**URL:** <https://talk.observablehq.com/t/formatting-checkbox-input-for-sql-where-clause/9817>\
**Category:** Help\
**Created:** [September 23, 2024, 1:27am UTC](https://talk.observablehq.com/t/formatting-checkbox-input-for-sql-where-clause/9817 "2024-09-23T01:27:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![OscarO](https://avatars.discourse-cdn.com/v4/letter/o/aca169/32.png) [@OscarO](https://talk.observablehq.com/u/OscarO)\
**Post date:** [September 23, 2024, 1:27am UTC](https://talk.observablehq.com/t/formatting-checkbox-input-for-sql-where-clause/9817/1 "2024-09-23T01:27:45Z")

</div>

Hello,

I am having trouble using a checkbox input in the where clause of a sql query with the built in launches dataset.

I have a checkbox input with the code:

const country = view(Inputs.checkbox([“United States”, “Soviet Union”], {label: “Country”, unique: true}));

I would like to do something to the effect of:

select \* from launches where state in (${country})

Any help or documentation is appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [September 23, 2024, 8:40am UTC](https://talk.observablehq.com/t/formatting-checkbox-input-for-sql-where-clause/9817/2 "2024-09-23T08:40:44Z")

</div>

Unfortunately this is a limitation of DuckDB-wasm. [Support array arguments in prepared statements · Issue #447 · duckdb/duckdb-wasm · GitHub](https://github.com/duckdb/duckdb-wasm/issues/447)

If you are using sql code blocks, a stopgap solution is to say

````sql
```sql
SELECT * FROM launches
  WHERE REGEXP_MATCHES(state, ${`^(${countries.join("|")})$`})
```

````

It is not as performant as using `IN()`, though.

For better performance, create the SQL query placeholders (`?`) in JavaScript like so:

````js
```js
sql([`
SELECT * FROM launches
  WHERE state IN (${Array.from(country, () => "?").join(", ")})
`], ...checkbox)
```

````

Or, to also account for the case where no country has been selected:

````js
```js
sql([`
SELECT * FROM launches
  WHERE state IN ('--'${", ?".repeat(country.length)})
`], ...checkbox)
```

````

where `'--'` is not a country.

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [September 23, 2024, 12:24pm UTC](https://talk.observablehq.com/t/formatting-checkbox-input-for-sql-where-clause/9817/3 "2024-09-23T12:24:29Z")

</div>

Also, please open a [GitHub discussion](https://github.com/observablehq/framework/discussions/) for further questions — we’re trying to move the conversations about Framework to a central place.
