Skip to content
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

Double-quoting column names in ON CONFLICT statement (PostgreSQL) #48

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/bulk_insert/worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ def on_conflict_statement
' ON CONFLICT DO NOTHING'
elsif is_postgres && update_duplicates
update_values = @columns.map do |column|
"#{column.name}=EXCLUDED.#{column.name}"
"\"#{column.name}\"=EXCLUDED.\"#{column.name}\""
end.join(', ')
' ON CONFLICT(' + update_duplicates.join(', ') + ') DO UPDATE SET ' + update_values
elsif adapter_name =~ /^mysql/i && update_duplicates
Expand Down
2 changes: 1 addition & 1 deletion test/bulk_insert/worker_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase
pgsql_worker.adapter_name = 'PostgreSQL'
pgsql_worker.add ["Yo", 15, false, nil, nil]

assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,0,NULL,NULL,'chartreuse') ON CONFLICT(greeting, age, happy) DO UPDATE SET greeting=EXCLUDED.greeting, age=EXCLUDED.age, happy=EXCLUDED.happy, created_at=EXCLUDED.created_at, updated_at=EXCLUDED.updated_at, color=EXCLUDED.color RETURNING id"
assert_equal pgsql_worker.compose_insert_query, "INSERT INTO \"testings\" (\"greeting\",\"age\",\"happy\",\"created_at\",\"updated_at\",\"color\") VALUES ('Yo',15,0,NULL,NULL,'chartreuse') ON CONFLICT(greeting, age, happy) DO UPDATE SET \"greeting\"=EXCLUDED.\"greeting\", \"age\"=EXCLUDED.\"age\", \"happy\"=EXCLUDED.\"happy\", \"created_at\"=EXCLUDED.\"created_at\", \"updated_at\"=EXCLUDED.\"updated_at\", \"color\"=EXCLUDED.\"color\" RETURNING id"
end

test "adapter dependent PostGIS methods" do
Expand Down