as the title states I am trying to update a jsonb field from inside R. I have several changes to apply. The original dataset is created by a third party application but needs to be corrected for several rows.
The following statement is working fine as a database statement:
UPDATE histories set meta=jsonb_set(meta,'{product}','"55-AB"') WHERE id = 17983;
Now, I need to update the "product" field for several different ids. Assume the following dataframe as an example:
df<-data.frame(product=c("55-AB","567-C","UTG-98"),
id=c(17983,54388,20000))
Usually I would use sql_glue
from the glue
package but I run out of quotes generating the above queries dynamically.
sql_glue("UPDATE histories set meta=jsonb_set(meta,'{product}','"{`df$product`}"') WHERE id = {`df$id`};")
Error: unexpected '{' in "sql_glue("UPDATE histories set meta=jsonb_set(meta,'{pesticide}','"{"
I am running into problems with the quotation. Any idea how to get around this?