On Sunday, November 29, 2015 at 9:01:24 PM UTC-8, Han Cheol Cho wrote:
>
> Hi all,
>
> I am trying to insert/update a record based on their existence in mysql db
> table.
> But it produces Sequel::UniqueConstraintViolation.
>
> A simplified code is something like below:
> ds = db[:mytable].where(:id => 1234)
> if ds.empty?
> db[:mytable].insert({:id => 1234, :value => "aaaa"})
> else
> db[:mytable].where(:id => 1234).update({:id => 1234, :value => "aaaa"})
>
You probably want to use on_duplicate_key_update:
http://sequel.jeremyevans.net/rdoc-adapters/classes/Sequel/MySQL/DatasetMethods.html#method-i-on_duplicate_key_update
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.