Fork me on GitHub
#sql
<
2019-10-21
>
murtaza5213:10:43

I am trying to generate sql for an update with a sub query . honesql generates the following -

"UPDATE sample SET available = FALSE FROM (SELECT id from sample where colour = red), AS subquery WHERE sample.id = subquery.id"
The problem is the , after the subquery, how do I get rid of it. My honesql -
(-> (helpers/update :sample)
    (helpers/sset {:available false})
    (helpers/from (find-sample-honesql m) (sql/raw "AS subquery"))
    (helpers/where [:= :sample.id :subquery.id])
    sql/format)

seancorfield16:10:08

You should be able to just provide an alias directly in from:

(helpers/from [(find-sample-honesql m) :subquery])
Does that not work @murtaza52?