Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using UPSERT PostgreSQL from Rails 4.2

How do I use "UPSERT" or "INSERT INTO likes (user_id,person_id) VALUES (32,64) ON CONFLICT (user_id,person_id) DO NOTHING" in PostgreSQL 9.5 on Rails 4.2?

like image 219
user3384741 Avatar asked Nov 21 '22 10:11

user3384741


1 Answers

Have a look at active_record_upsert gem here: https://github.com/jesjos/active_record_upsert. This does the upsert, but obviously only on Postgres 9.5+.

like image 53
pungoyal Avatar answered Nov 22 '22 23:11

pungoyal