On Sunday, January 26, 2020 at 4:48:26 AM UTC-8, Tiago Cardoso wrote: > > Hi there, > > I've been struggling to find examples on how to do atomic > increment/decrement operations on a column, which may or may not update the > "updated_at" timestamps. > > Specifically, something like the AR#increment and AR#decrement methods, > which result in smith like this: > > "UPDATE this_table SET counter = COALESCE(counter, 0) + 1" >
A basic translation of the query: DB[:this_table].update(:counter=>Sequel.expr{COALESCE(:counter,0)+1}) In general, true updated_at timestamps should be implemented via triggers, in which case you shouldn't need more than the above to also update that column. However, if you don't want to use triggers: DB[:this_table].update(:counter=>Sequel.expr{COALESCE(:counter,0)+1}, :updated_at=>Sequel::CURRENT_TIMESTAMP) Thanks, Jeremy -- You received this message because you are subscribed to the Google Groups "sequel-talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to sequel-talk+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sequel-talk/45b88fee-a458-463d-a5b3-82b7af3b6e7d%40googlegroups.com.