# database cells: can I inject references to other cells?

**URL:** <https://talk.observablehq.com/t/database-cells-can-i-inject-references-to-other-cells/6559>\
**Category:** Help\
**Created:** [May 16, 2022, 4:41am UTC](https://talk.observablehq.com/t/database-cells-can-i-inject-references-to-other-cells/6559 "2022-05-16T04:41:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [May 16, 2022, 4:41am UTC](https://talk.observablehq.com/t/database-cells-can-i-inject-references-to-other-cells/6559/1 "2022-05-16T04:41:11Z")

</div>

If I am running a query within a database cell like `SELECT * FROM table_name` , is it still possible to pass in a value from another cell? I would like to pass in `table_name` as a variable , such as with `viewof variable = Inputs.select(array_with_table_names)` . I don’t see how to ‘escape’ into JavaScript in a database cell using patterns like `SELECT * FROM ${variable}`

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [May 16, 2022, 9:35pm UTC](https://talk.observablehq.com/t/database-cells-can-i-inject-references-to-other-cells/6559/2 "2022-05-16T21:35:40Z")

</div>

You can reference a dynamic _value_, but in most database client implementations (including PostgreSQL), you can’t reference a dynamic _table_ or _column_ or _syntax_.

So, you can say

```sql
SELECT * FROM users WHERE name = ${x};

```

but you can’t say

```sql
SELECT * FROM ${x} WHERE name = 'foo';

```

and you also can’t say something like

```sql
SELECT ${x} FROM users WHERE name = 'foo';

```

If you want to do those things, you could construct the SQL query dynamically, but you can’t do that using an Observable SQL cell (or the db.sql tagged template literal). You’d have to construct the SQL yourself, and you’d be responsible for any escaping.

---

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [May 16, 2022, 10:46pm UTC](https://talk.observablehq.com/t/database-cells-can-i-inject-references-to-other-cells/6559/3 "2022-05-16T22:46:18Z")

</div>

Thank you!

---

<div class="post-metadata">

**Author:** ![aaronkyle](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/aaronkyle/32/8106_2.png) [@aaronkyle](https://talk.observablehq.com/u/aaronkyle)\
**Post date:** [May 18, 2022, 6:56am UTC](https://talk.observablehq.com/t/database-cells-can-i-inject-references-to-other-cells/6559/4 "2022-05-18T06:56:06Z")

</div>

> but you can’t do that using an Observable SQL cell (_or the db.sql tagged template literal_) [emphasis added]

… just a quick note: it seems you _can_ do this? 🙂

i.e.

```auto
db_attribute_data = db.query(`SELECT * FROM ${db_explore}`)

```

totally works!

… (though after posting I realize I am likely mistaken, as I am using a JavaScript cell rather than the `db.sql` tagged template literal)
