{"action":"created","issue":{"url":"https://api.github.com/repos/zdennis/activerecord-import/issues/568","repository_url":"https://api.github.com/repos/zdennis/activerecord-import","labels_url":"https://api.github.com/repos/zdennis/activerecord-import/issues/568/labels{/name}","comments_url":"https://api.github.com/repos/zdennis/activerecord-import/issues/568/comments","events_url":"https://api.github.com/repos/zdennis/activerecord-import/issues/568/events","html_url":"https://github.com/zdennis/activerecord-import/issues/568","id":383307889,"node_id":"MDU6SXNzdWUzODMzMDc4ODk=","number":568,"title":"on_duplicate_key_update {columns: :all} updates conflicted columns","user":{"login":"abinoda","id":50083,"node_id":"MDQ6VXNlcjUwMDgz","avatar_url":"https://avatars0.githubusercontent.com/u/50083?v=4","gravatar_id":"","url":"https://api.github.com/users/abinoda","html_url":"https://github.com/abinoda","followers_url":"https://api.github.com/users/abinoda/followers","following_url":"https://api.github.com/users/abinoda/following{/other_user}","gists_url":"https://api.github.com/users/abinoda/gists{/gist_id}","starred_url":"https://api.github.com/users/abinoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abinoda/subscriptions","organizations_url":"https://api.github.com/users/abinoda/orgs","repos_url":"https://api.github.com/users/abinoda/repos","events_url":"https://api.github.com/users/abinoda/events{/privacy}","received_events_url":"https://api.github.com/users/abinoda/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2018-11-21T22:04:56Z","updated_at":"2018-11-22T02:15:47Z","closed_at":null,"author_association":"NONE","body":"Related to https://github.com/zdennis/activerecord-import/issues/567. I'm seeing that using the `{columns: :all}` option for `on_duplicate_key_update` results in the conflict target column(s) included in the `DO UPDATE` columns. In my case, the target columns have a composite index with a constraint so it does not make sense for either of those target columns to be updated ON CONFLICT. Is there a reason why this library attempts to update those columns? Should this behavior be removed? Or would it be useful if there were an option like `columns: :not_target` that updated all columns but excluded te ones specified in `conflict_target`?\r\n\r\nThe steps to reproduce are below:\r\n\r\n```ruby\r\ncreate_table \"github_repos\", force: :cascade do |t|\r\n  t.bigint \"org_id\"\r\n  t.bigint \"github_id\"\r\n  t.string \"name\"\r\n  t.string \"description\"\r\n  t.index [\"org_id\", \"github_id\"], name: \"unique_repos\", unique: true\r\nend\r\n\r\narr = [\r\n  {org_id: 1, github_id: 1, name: 'foo', description: 'hello'}\r\n]\r\n\r\nGithubRepo.import(arr, on_duplicate_key_update: {\r\n  conflict_target: [:org_id, :github_id],\r\n  columns:         :all \r\n})\r\n```\r\n\r\nThis results in the following query:\r\n```sql\r\nINSERT INTO \"github_repos\" (\"org_id\",\"github_id\",\"name\",\"description\") VALUES (1,1,'foo''hello')\r\nON CONFLICT (org_id, github_id)\r\nDO UPDATE SET \"org_id\"=EXCLUDED.\"org_id\",\"github_id\"=EXCLUDED.\"github_id\",\"name\"=EXCLUDED.\"name\",\"description\"=EXCLUDED.\"description\"\r\nRETURNING \"id\"\r\n```"},"comment":{"url":"https://api.github.com/repos/zdennis/activerecord-import/issues/comments/440891902","html_url":"https://github.com/zdennis/activerecord-import/issues/568#issuecomment-440891902","issue_url":"https://api.github.com/repos/zdennis/activerecord-import/issues/568","id":440891902,"node_id":"MDEyOklzc3VlQ29tbWVudDQ0MDg5MTkwMg==","user":{"login":"abinoda","id":50083,"node_id":"MDQ6VXNlcjUwMDgz","avatar_url":"https://avatars0.githubusercontent.com/u/50083?v=4","gravatar_id":"","url":"https://api.github.com/users/abinoda","html_url":"https://github.com/abinoda","followers_url":"https://api.github.com/users/abinoda/followers","following_url":"https://api.github.com/users/abinoda/following{/other_user}","gists_url":"https://api.github.com/users/abinoda/gists{/gist_id}","starred_url":"https://api.github.com/users/abinoda/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abinoda/subscriptions","organizations_url":"https://api.github.com/users/abinoda/orgs","repos_url":"https://api.github.com/users/abinoda/repos","events_url":"https://api.github.com/users/abinoda/events{/privacy}","received_events_url":"https://api.github.com/users/abinoda/received_events","type":"User","site_admin":false},"created_at":"2018-11-22T02:15:47Z","updated_at":"2018-11-22T02:15:47Z","author_association":"NONE","body":"@zdennis @jkowens Yep, the suggestion by @jkowens works. I'll probably create a method in my base model like below. `upsert_keys` is a class method I use via https://github.com/jesjos/active_record_upsert.\r\n\r\n```ruby\r\nclass ApplicationRecord < ActiveRecord::Base\r\n  def self.bulk_upsert(arr)\r\n    import(arr, on_duplicate_key_update: {\r\n      conflict_target: upsert_keys,\r\n      columns: column_names.map(&:to_sym) - primary_key.to_sym - upsert_keys\r\n    })\r\n  end\r\nend\r\n```"}}
{"actor":{"display_login":"abinoda"}}