Fork me on GitHub
#honeysql
<
2022-05-03
>
snoe20:05:17

Hi, is it possible to alias a clause with named columns? My closest attempt is this:

(hsql/format {:select [:nums.tens :nums.ones]
              :from [[{:values [[1,10] [2,20]]} [:nums [:ones :tens]]]]})
=actual> "SELECT nums.tens, nums.ones FROM (VALUES (1, 10), (2, 20)) nums ones tens"
=desire> "SELECT nums.tens, nums.ones FROM (VALUES (1, 10), (2, 20)) nums(ones, tens)"

seancorfield21:05:00

Is this what you're trying to achieve?

dev=> (hsql/format {:select [:nums.tens :nums.ones]
 #_=>               :from [[{:values [[1,10] [2,20]]} [:nums [:composite :ones :tens]]]]})
["SELECT nums.tens, nums.ones FROM (VALUES (?, ?), (?, ?)) AS nums (ones, tens)" 1 10 2 20]

seancorfield21:05:52

(HoneySQL 2.x -- :composite does not exist in 1.x I don't think)

snoe21:05:06

ah, perfect, thank you

snoe21:05:39

we're still on 1.x but maybe i can backport in our code

seancorfield21:05:05

You can use 2.x and 1.x side-by-side, even in the same namespace, so you could add 2.x and use it just for this one query 🙂

seancorfield21:05:35

We are using a mix of 1.x and 2.x at work so we can migrate one query at a time if we need to.