# Text Input and dynamic SQL Queries

**URL:** <https://talk.observablehq.com/t/text-input-and-dynamic-sql-queries/8970>\
**Category:** Help\
**Created:** [March 21, 2024, 9:10am UTC](https://talk.observablehq.com/t/text-input-and-dynamic-sql-queries/8970 "2024-03-21T09:10:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![saptarshiguha](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/saptarshiguha/32/8656_2.png) [@saptarshiguha](https://talk.observablehq.com/u/saptarshiguha)\
**Post date:** [March 21, 2024, 9:10am UTC](https://talk.observablehq.com/t/text-input-and-dynamic-sql-queries/8970/1 "2024-03-21T09:10:00Z")

</div>

Hello,  
Always starting with a big thanks! I have some code here

````auto
```js
const db = DuckDBClient.of({foo: FileAttachment("./data/poem_data.parquet")});
const text = view(Inputs.textarea({placeholder:'Write your SQL query here', submit: true, rows: 6}));

````

and then use this string to run an SQL query using DuckDB

````auto
```js
const ans = db.sql`${text}`

````

but I get the error

 ![Screenshot 2024-03-21 at 2.09.30 AM](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/b/bed47ef8e3e8d773bad2a923223e0a0534b5d2a7.png)

Thanks much  
Saptarshi

---

<div class="post-metadata">

**Author:** ![mootari](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mootari/32/581_2.png) [@mootari](https://talk.observablehq.com/u/mootari)\
**Post date:** [March 21, 2024, 11:02am UTC](https://talk.observablehq.com/t/text-input-and-dynamic-sql-queries/8970/2 "2024-03-21T11:02:48Z")

</div>

DuckDBClient.sql replaces interpolated values with placeholders before passing them on as parameters. Your call is equivalent to

```js
const ans = db.query("?", [text])

```

If you want to pass the raw string as query you’ll have to call .query instead:

```js
const ans = db.query(text)

```

You can find more information about the available methods in the Framework docs: [DuckDB | Observable Framework](https://observablehq.com/framework/lib/duckdb)

---

<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:** [March 21, 2024, 11:02am UTC](https://talk.observablehq.com/t/text-input-and-dynamic-sql-queries/8970/3 "2024-03-21T11:02:57Z")

</div>

Yes, that’s expected. The `sql` template literal will create queries with placeholders for values (which will then be properly escaped), but it does not build arbitrary queries. Instead you might want to do something like:

```js
const ans = db.sql([text]);

```

---

<div class="post-metadata">

**Author:** ![saptarshiguha](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/saptarshiguha/32/8656_2.png) [@saptarshiguha](https://talk.observablehq.com/u/saptarshiguha)\
**Post date:** [March 21, 2024, 4:13pm UTC](https://talk.observablehq.com/t/text-input-and-dynamic-sql-queries/8970/4 "2024-03-21T16:13:53Z")

</div>

Thank you both of you. I am in the enjoyable spot of learning JavaScript and observable framework at the same time :). Yesterday I was reading for the first time template literals …

Interestingly chatgpt (and its ilk) has helped out but doesnt compete at all with experts here.

Thanks again  
Saptarshi
