Hi Jeremy,

I saw some historical posts about batch updates like this one:

https://groups.google.com/g/sequel-talk/c/uV7PRbEvQj0/m/lCvZaLx8AAAJ

It feels a little "hacky" to say insert this record with a unique primary 
key that already exists...when you get an error, then update it. 

I've been using a solution like this:

    run <<-SQL
          update user_expo_push_tokens as uept set -- postgres FTW
            device_id = ud2.device_id
          from (values
            #{updates.join(", ")}
          ) as ud2(installation_id, device_id)
          where ud2.installation_id = uept.installation_id;
    SQL

This also works in the case where the values are not a primary key or have 
a unique index to throw the "on duplicate key update" logic. 

Is there a way to accomplish this without having to drop to straight sql?



-- 
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/c8d22b8a-9b73-4db2-a41a-9dc3ee3ef5bcn%40googlegroups.com.

Reply via email to