sql

grav 2025-10-30T10:51:20.648959Z

This is a small footgun (at least for me 😅)

(next.jdbc/execute conn ["SELECT count(*) FROM mytable"])
=> [{:count(*) 42}]

😲 1
grav 2025-10-30T10:54:01.816229Z

Is there an option for execute so that the key isn't :count(*) (which doesn't seem to be a valid keyword), without changing the query?

igrishaev 2025-10-30T12:41:20.389809Z

1. You can construct the keyword from a string:

(keyword "count(*)")
:count(*)
define it as a constant and then
(-> result first (get COUNT_KEYWORD))
2. pass another result-set builder to your query, for example the one that produces a flat matrix (array or something). The first row will be a header, and the second row represents values:
(-> result second first)

2025-10-30T12:42:32.317439Z

can you give the count a name? count(*) as cnt

igrishaev 2025-10-30T12:43:32.723789Z

if your query has no other columns, just take the first row and the first map entry, and its value :

(-> result first first val)

seancorfield 2025-10-30T14:19:58.922669Z

count(*) is what JDBC returns for the column label if there is no alias. next.jdbc is a *very* thin wrapper here 🙂

nikolavojicic 2025-10-30T16:17:02.767279Z

@igrishaev minor note: you can ffirst instead of first first

seancorfield 2025-10-30T16:21:30.688249Z

Another option: (plan/select-one! ds (comp first vals) ["select count(*) from user"]) 🙂

👍 1
onetom 2025-11-11T08:26:06.807729Z

why not specify a column alias explicitly, like SELECT count(*) AS 'frob/count' FROM mytable? (the AS is optional, btw and the column alias quoting might be different, depending on the SQL dialect)

grav 2025-11-11T08:40:49.309719Z

In this case I cannot control the query