From be19ace9b0d64cd64480c971863a0f36bdbaa8e9 Mon Sep 17 00:00:00 2001 From: Nikita Anistratenko Date: Thu, 12 Dec 2019 14:55:01 +0300 Subject: [PATCH 1/7] use double-quote for column-name in update duplicates psql --- lib/bulk_insert/worker.rb | 2 +- test/bulk_insert/worker_test.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/bulk_insert/worker.rb b/lib/bulk_insert/worker.rb index a16a938..0ce64c6 100644 --- a/lib/bulk_insert/worker.rb +++ b/lib/bulk_insert/worker.rb @@ -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 diff --git a/test/bulk_insert/worker_test.rb b/test/bulk_insert/worker_test.rb index 735972b..a7c02ab 100644 --- a/test/bulk_insert/worker_test.rb +++ b/test/bulk_insert/worker_test.rb @@ -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 From 49bbf516d693c9f6fcea63d5ab12d7358932ea59 Mon Sep 17 00:00:00 2001 From: Nikita Anistratenko Date: Thu, 12 Dec 2019 15:40:33 +0300 Subject: [PATCH 2/7] added ON CONFLICT UPDATE for bulk insert wrapper --- .idea/.gitignore | 2 + .idea/.rakeTasks | 7 ++++ .idea/bulk_insert.iml | 16 ++++++++ .idea/inspectionProfiles/Project_Default.xml | 39 ++++++++++++++++++++ .idea/misc.xml | 4 ++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ .rakeTasks | 7 ++++ lib/bulk_insert/worker.rb | 1 + 9 files changed, 90 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/.rakeTasks create mode 100644 .idea/bulk_insert.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .rakeTasks diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..e7e9d11 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,2 @@ +# Default ignored files +/workspace.xml diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks new file mode 100644 index 0000000..c6865d9 --- /dev/null +++ b/.idea/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/.idea/bulk_insert.iml b/.idea/bulk_insert.iml new file mode 100644 index 0000000..eeb328f --- /dev/null +++ b/.idea/bulk_insert.iml @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..b4ba2a5 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,39 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..72ee4bf --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..4e903a8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.rakeTasks b/.rakeTasks new file mode 100644 index 0000000..c6865d9 --- /dev/null +++ b/.rakeTasks @@ -0,0 +1,7 @@ + + diff --git a/lib/bulk_insert/worker.rb b/lib/bulk_insert/worker.rb index 0ce64c6..555646e 100644 --- a/lib/bulk_insert/worker.rb +++ b/lib/bulk_insert/worker.rb @@ -169,3 +169,4 @@ def on_conflict_statement end end end + From b3a43584dabe639c3952093910a293e5c20bf1d7 Mon Sep 17 00:00:00 2001 From: Nikita Anistratenko Date: Thu, 12 Dec 2019 15:40:51 +0300 Subject: [PATCH 3/7] added ON CONFLICT UPDATE for bulk insert wrapper --- lib/bulk_insert/worker.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/bulk_insert/worker.rb b/lib/bulk_insert/worker.rb index 555646e..b32d1d1 100644 --- a/lib/bulk_insert/worker.rb +++ b/lib/bulk_insert/worker.rb @@ -170,3 +170,4 @@ def on_conflict_statement end end + \ No newline at end of file From 3ad73325f2301516bf6e3cc9cade8fd856393737 Mon Sep 17 00:00:00 2001 From: Nikita Anistratenko Date: Thu, 12 Dec 2019 15:48:45 +0300 Subject: [PATCH 4/7] remove .idea files --- lib/bulk_insert/worker.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/bulk_insert/worker.rb b/lib/bulk_insert/worker.rb index b32d1d1..44f22ab 100644 --- a/lib/bulk_insert/worker.rb +++ b/lib/bulk_insert/worker.rb @@ -168,6 +168,4 @@ def on_conflict_statement end end end -end - - \ No newline at end of file +end \ No newline at end of file From 0a27d25d05f05edccea0a203c69568f2c53218d1 Mon Sep 17 00:00:00 2001 From: Nikita Anistratenko Date: Thu, 12 Dec 2019 15:49:30 +0300 Subject: [PATCH 5/7] remove .idea files --- .idea/.gitignore | 2 - .idea/.rakeTasks | 7 ---- .idea/bulk_insert.iml | 16 -------- .idea/inspectionProfiles/Project_Default.xml | 39 -------------------- .idea/misc.xml | 4 -- .idea/modules.xml | 8 ---- .idea/vcs.xml | 6 --- 7 files changed, 82 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/.rakeTasks delete mode 100644 .idea/bulk_insert.iml delete mode 100644 .idea/inspectionProfiles/Project_Default.xml delete mode 100644 .idea/misc.xml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index e7e9d11..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# Default ignored files -/workspace.xml diff --git a/.idea/.rakeTasks b/.idea/.rakeTasks deleted file mode 100644 index c6865d9..0000000 --- a/.idea/.rakeTasks +++ /dev/null @@ -1,7 +0,0 @@ - - diff --git a/.idea/bulk_insert.iml b/.idea/bulk_insert.iml deleted file mode 100644 index eeb328f..0000000 --- a/.idea/bulk_insert.iml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml deleted file mode 100644 index b4ba2a5..0000000 --- a/.idea/inspectionProfiles/Project_Default.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 72ee4bf..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 4e903a8..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 94a25f7..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file From 7354c6913d3c8e3774cf7bb0909adda74da6da6d Mon Sep 17 00:00:00 2001 From: Nikita Anistratenko Date: Thu, 12 Dec 2019 15:51:01 +0300 Subject: [PATCH 6/7] delete .rakeTasks file --- .rakeTasks | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 .rakeTasks diff --git a/.rakeTasks b/.rakeTasks deleted file mode 100644 index c6865d9..0000000 --- a/.rakeTasks +++ /dev/null @@ -1,7 +0,0 @@ - - From 905dc18079b3ecf2c61e04dbd146297fe01f5c1a Mon Sep 17 00:00:00 2001 From: Nikita Anistratenko Date: Thu, 12 Dec 2019 21:53:26 +0300 Subject: [PATCH 7/7] added empty line to lib/worker.rb --- lib/bulk_insert/worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/bulk_insert/worker.rb b/lib/bulk_insert/worker.rb index 44f22ab..0ce64c6 100644 --- a/lib/bulk_insert/worker.rb +++ b/lib/bulk_insert/worker.rb @@ -168,4 +168,4 @@ def on_conflict_statement end end end -end \ No newline at end of file +end