Fork me on GitHub
#sql
<
2021-08-26
>
finchharold11:08:42

Hi all, how to do this in clojure? UPDATE product SET attributes = attributes || '{"width":"100cm"}' WHERE id = 1;

finchharold11:08:58

where attributes is of json

finchharold11:08:19

using next.jdbc or sqlingvo?

emccue11:08:21

is that valid sql for your db?

emccue11:08:59

(jdbc/execute db ["UPDATE product SET attributes = attributes || '{"width":"100cm"}' WHERE id = ?" id])

finchharold11:08:44

Not working that way

finchharold11:08:16

(j/execute! db
                ["UPDATE product SET atrributes = atrributes || '{"width": width}' WHERE id = w-id"])
Here I want width and id values to be taken from arg of function

finchharold11:08:55

What I am trying is to update the jsob value of attributes without replacing the existing value

finchharold11:08:41

This worked fine UPDATE product SET attributes = attributes || '{"width":"100cm"}' WHERE id = 1;`

finchharold11:08:07

but in clojure I have to get the values for width and id from other variables

emccue11:08:30

did you end up just putting ? in place of "100cm"?

finchharold11:08:02

No, for the entire - '{"width":"100cm"}' kept ?