Thanks in advance for your help in this matter.
I have a model in rails that includes a postgresql column.
I want to add data (i.e. mycolumn = mycolumn || newdata) to an existing column. The Sql I want to create will look like this:
update MyOjbs set mycolumn = mycolumn || newdata where id = 12;
I would rather not select the data, update the attribute, and then write the new data to the database. A text column can grow relatively large, and I would prefer not to read this data if I don't need it.
I do not want to do this:
@myinstvar = MyObj.select(:mycolumn).find(12)
newdata = @myinstvar.mycolumn.to_s + newdata
@myinstvar.update_attribute(:mycolumn, newdata)
Do I need to execute an raw sql transaction to complete this?
source
share