Sitelet https://github.com/jamis/bulk_insert/commit/8dd3eb7209d37e5cb4c07cd7f427aea08e2e68bc
Skip to content

Commit 8dd3eb7

Browse files
authored
Merge pull request #60 from nlpgo/master
Worker options ignore: false and update_duplicates: false cause an error when using postgresql_adapter.
2 parents 22ec5b2 + 91d3b6e commit 8dd3eb7

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎lib/bulk_insert/statement_adapters/postgresql_adapter.rb‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def on_conflict_statement(columns, ignore, update_duplicates)
1515
"#{column.name}=EXCLUDED.#{column.name}"
1616
end.join(', ')
1717
' ON CONFLICT(' + update_duplicates.join(', ') + ') DO UPDATE SET ' + update_values
18+
else
19+
''
1820
end
1921
end
2022

‎test/bulk_insert/worker_test.rb‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,26 @@ class BulkInsertWorkerTest < ActiveSupport::TestCase
353353
end
354354
end
355355

356+
test "adapter dependent postgresql methods (no ignore, no update_duplicates)" do
357+
connection = Testing.connection
358+
connection.stub :adapter_name, 'PostgreSQL' do
359+
pgsql_worker = BulkInsert::Worker.new(
360+
connection,
361+
Testing.table_name,
362+
'id',
363+
%w(greeting age happy created_at updated_at color),
364+
500, # batch size
365+
false, # ignore
366+
false, # update duplicates
367+
true # return primary keys
368+
)
369+
370+
pgsql_worker.add ["Yo", 15, false, nil, nil]
371+
372+
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') RETURNING id"
373+
end
374+
end
375+
356376
test "adapter dependent postgresql methods (with update_duplicates)" do
357377
connection = Testing.connection
358378
connection.stub :adapter_name, 'PostgreSQL' do

0 commit comments

Comments
 (0)