lib/pgsync/task.rb in pgsync-0.6.5 vs lib/pgsync/task.rb in pgsync-0.6.6

- old
+ new

@@ -138,12 +138,16 @@ action = if opts[:preserve] "NOTHING" else # overwrite or sql clause setter = shared_fields.reject { |f| primary_key.include?(f) }.map { |f| "#{quote_ident(f)} = EXCLUDED.#{quote_ident(f)}" } - "UPDATE SET #{setter.join(", ")}" + if setter.any? + "UPDATE SET #{setter.join(", ")}" + else + "NOTHING" + end end - destination.execute("INSERT INTO #{quoted_table} (SELECT * FROM #{quote_ident_full(temp_table)}) ON CONFLICT (#{on_conflict}) DO #{action}") + destination.execute("INSERT INTO #{quoted_table} (#{fields}) (SELECT #{fields} FROM #{quote_ident_full(temp_table)}) ON CONFLICT (#{on_conflict}) DO #{action}") else # use delete instead of truncate for foreign keys if opts[:defer_constraints] || opts[:defer_constraints_v2] destination.execute("DELETE FROM #{quoted_table}") else