activerecord-import: on_duplicate_key_update {columns: :all} updates conflicted columns
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
?
The steps to reproduce are below:
create_table "github_repos", force: :cascade do |t|
t.bigint "org_id"
t.bigint "github_id"
t.string "name"
t.string "description"
t.index ["org_id", "github_id"], name: "unique_repos", unique: true
end
arr = [
{org_id: 1, github_id: 1, name: 'foo', description: 'hello'}
]
GithubRepo.import(arr, on_duplicate_key_update: {
conflict_target: [:org_id, :github_id],
columns: :all
})
This results in the following query:
INSERT INTO "github_repos" ("org_id","github_id","name","description") VALUES (1,1,'foo','hello')
ON CONFLICT (org_id, github_id)
DO UPDATE SET "org_id"=EXCLUDED."org_id","github_id"=EXCLUDED."github_id","name"=EXCLUDED."name","description"=EXCLUDED."description"
RETURNING "id"
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (2 by maintainers)
@jkowens Working on it!