# SQL restructuring and confusion about what the sql block returns

**URL:** <https://talk.observablehq.com/t/sql-restructuring-and-confusion-about-what-the-sql-block-returns/9841>\
**Category:** Help\
**Created:** [September 29, 2024, 1:39pm UTC](https://talk.observablehq.com/t/sql-restructuring-and-confusion-about-what-the-sql-block-returns/9841 "2024-09-29T13:39:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eamcvey](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/eamcvey/32/9270_2.png) [@eamcvey](https://talk.observablehq.com/u/eamcvey)\
**Post date:** [September 29, 2024, 1:39pm UTC](https://talk.observablehq.com/t/sql-restructuring-and-confusion-about-what-the-sql-block-returns/9841/1 "2024-09-29T13:39:58Z")

</div>

I’m new to Observable Framework and I’m not a javascript programmer. I’m trying to port a dashboard I created successfully with Quarto + Observable + DuckDB to Observable Framework and I’m running into some problems with simple things.

Specifically, I want to use the results of a sql query to populate a select input. I have this block, but the resulting `target_list` is a key-value array. I don’t seem to be able to use things like `map()` on this object. Arrow Table functions also don’t seem to be available. I though the sql block returned an Arrow table, so I’m confused about what I’m dealing with.

````auto
```sql id=target_list
SELECT DISTINCT Target FROM targets
```

````

I tried destructuring but that only ever seems to return the first row, or in the latter case, the first result broken up by letter. I really don’t understand what’s going on here. What I’m trying to accomplish here seems like it would be a common pattern (though I can’t find an example in which an Input is populated by a sql query result) – there’s an easy way to accomplish this, right?

````auto
```sql id="[{'Target': target_list2}]"
SELECT DISTINCT Target FROM targets
```

```sql id=[target_list3]
SELECT DISTINCT Target FROM targets
```

````

---

<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 29, 2024, 2:28pm UTC](https://talk.observablehq.com/t/sql-restructuring-and-confusion-about-what-the-sql-block-returns/9841/2 "2024-09-29T14:28:07Z")

</div>

The result is an [Arrow table](https://arrow.apache.org/docs/cpp/tables.html), you can transform it with, _e.g._:

> Array.from(target\_list, (d) =\> ({…d})

or _table_.toArray

> target\_list.toArray()

In the future please open a [GitHub Discussion](https://github.com/observablehq/framework/discussions/) instead. We’re using GitHub now for support around our open-source projects. Thank you!

---

<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:** [September 29, 2024, 3:08pm UTC](https://talk.observablehq.com/t/sql-restructuring-and-confusion-about-what-the-sql-block-returns/9841/3 "2024-09-29T15:08:26Z")

</div>

Yes, please use a GitHub Discussion for open-source related topics — we’d really like to consolidate discussions there so people don’t have to search in multiple places to find help.

The `ARRAY` SQL function might be helpful here. This lets you return a single row with multiple values, rather than multiple rows. Then you can destructure the array-valued column into a variable:

````auto
```sql id=[{targets}]
SELECT ARRAY(SELECT DISTINCT Target FROM targets) AS targets;
```

````

Technically this will give you a `Utf8Vector` rather than a `string[]`, but since Arrow vectors are iterable, you can use it directly to create an input. For example, here’s a radio input:

````auto
```js
const target = view(Inputs.radio(targets), {label: "Target"});
```

````

The value of `target` is now a string (or null if the user hasn’t chosen a target yet, but you can also preset the initial value of the radio if you like).
