# How to qualify a column name in a SQL query passed to emacsql?

**URL:** https://org-roam.discourse.group/t/how-to-qualify-a-column-name-in-a-sql-query-passed-to-emacsql/3756
**Category:** Troubleshooting
**Created:** [March 1, 2025, 3:08pm UTC](https://org-roam.discourse.group/t/how-to-qualify-a-column-name-in-a-sql-query-passed-to-emacsql/3756 "2025-03-01T15:08:34Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JeffBrown](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jeffbrown/32/254_2.png) [@JeffBrown](https://org-roam.discourse.group/u/JeffBrown)
#### Post date: [March 1, 2025, 3:08pm UTC](https://org-roam.discourse.group/t/how-to-qualify-a-column-name-in-a-sql-query-passed-to-emacsql/3756/1 "2025-03-01T15:08:34Z")

</div>

I also posted this question on the Emacs StackExchange: [sqlite - How to qualify a column name in a SQL query passed to emacsql? - Emacs Stack Exchange](https://emacs.stackexchange.com/questions/83191/how-to-qualify-a-column-name-in-a-sql-query-passed-to-emacsql)

Here’s the question in its entirety:

# Some context

I’m querying my org-roam database, which is using the default sqlite3 format.

# The code I expected to work

When I pass the following query to `emacsql`:

```auto
[:select [source title nodes.properties]
         :from links
         :inner-join nodes :on (= source id)
         :where (= dest $s1)]

```

the `source` and `title` columns contain what I expect, but the `properties` column merely contains the symbol `nodes.properties`, rather than the content of the `properties` column from `nodes`.

# Further explorations

I can even replace `nodes.properties` with `nodes.sauerkraut` – a column that does not exist – and similarly, the third element of each row of the response will just be the symbole `nodes.sauerkraut`.

If I remove the qualification, putting `sauerkraut` rather than `nodes.sauerkraut`, I get a reasonable error:

```auto
Debugger entered--Lisp error: (emacsql-error nil nil nil ("SQL logic error" "no such column: sauerkraut" 1 1))

```

---

<div class="post-metadata">

### Author: ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)
#### Post date: [March 1, 2025, 4:16pm UTC](https://org-roam.discourse.group/t/how-to-qualify-a-column-name-in-a-sql-query-passed-to-emacsql/3756/2 "2025-03-01T16:16:44Z")

</div>

Use “:”.  
This seems to work on my end – I get a result of the query.

```auto
(org-roam-db-query
 [:select [source title nodes:properties]
          :from links
          :inner-join nodes :on (= source id)
          :where (= dest $s1)] "2021-01-16T121946")

```

---

<div class="post-metadata">

### Author: ![nobiot](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/nobiot/32/159_2.png) [@nobiot](https://org-roam.discourse.group/u/nobiot)
#### Post date: [March 1, 2025, 4:22pm UTC](https://org-roam.discourse.group/t/how-to-qualify-a-column-name-in-a-sql-query-passed-to-emacsql/3756/3 "2025-03-01T16:22:08Z")

</div>

Alternatively, as you seem to be familiar with SQL, you can use the normal SQL statements by passing them as a string. See how the function `org-roam-node-list` does this.

---

<div class="post-metadata">

### Author: ![JeffBrown](https://yyz2.discourse-cdn.com/free1/user_avatar/org-roam.discourse.group/jeffbrown/32/254_2.png) [@JeffBrown](https://org-roam.discourse.group/u/JeffBrown)
#### Post date: [March 1, 2025, 4:37pm UTC](https://org-roam.discourse.group/t/how-to-qualify-a-column-name-in-a-sql-query-passed-to-emacsql/3756/4 "2025-03-01T16:37:42Z")

</div>

Works for me too! Woohoo! Thanks again (for the tenth time?), @nobiot!
