-
Notifications
You must be signed in to change notification settings - Fork 618
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support INSERT ... ON CONFLICT DO NOTHING/UPDATE (also known as UPSERT) for PostgreSQL #187
Comments
@JustusLauten ooh, that will be nice for Postgres to get. Any idea what version they are planning on including this in? |
Postgres 9.5: https://wiki.postgresql.org/wiki/UPSERT |
@zdennis any chance we could get this implemented? |
^^ Quick and dirty. Maybe someone wants to take it on and make it merge worthy. |
Postgres 9.5 was released yesterday with the UPSERT feature. 👍 |
It's butter |
+1 |
The implementation for UPSERT with Postgres is going to have to be slightly different than that for MySQL. Postgres requires that the constraint that may result in a duplicate key error be specified, where MySQL does not. It can referenced by either column name(s):
Or by constraint name:
The documentation indicates column name should be preferred (see the "Tip" for on conflict clause). That being said, I was thinking it would be acceptable to just make column names the requirement for identifying the unique constraint. Any thoughts about what this more explicit syntax should look like? I was thinking that even though it doesn't match the Postgres syntax, it might be nice to stick with the :on_duplicate_key_update parameter. This would be a hash with an attribute for the key and one for the columns that should be updated.
Thoughts on the naming? Other suggestions? |
The feature exists already for MySQL databases and can be used with the :on_duplicate_key_update parameter. Upcoming versions of PostgreSQL will feature a similar functionality:
http://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=168d5805e4c08bed7b95d351bf097cff7c07dd65
It would be cool to see this feature in activerecord-import, also for PostgreSQL databases.
The text was updated successfully, but these errors were encountered: