Formatting checkbox input for sql where clause

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

Unfortunately this is a limitation of DuckDB-wasm. Support array arguments in prepared statements · Issue #447 · duckdb/duckdb-wasm · GitHub

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

```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
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
sql([`
SELECT * FROM launches
  WHERE state IN ('--'${", ?".repeat(country.length)})
`], ...checkbox)
```

where '--' is not a country.

Also, please open a GitHub discussion for further questions — we’re trying to move the conversations about Framework to a central place.