diff --git a/lib/polo/adapters/postgres.rb b/lib/polo/adapters/postgres.rb index 6bd1c37..24e89b8 100644 --- a/lib/polo/adapters/postgres.rb +++ b/lib/polo/adapters/postgres.rb @@ -29,6 +29,11 @@ def ignore_transform(inserts, records) table_name = record.class.arel_table.name end insert = insert.gsub(/VALUES \((.+)\)$/m, 'SELECT \\1') + + if record.class.respond_to?(:columns_hash) && ![:integer, :float, :decimal].include?(record.class.columns_hash["id"].type) + id = "'#{id}'" + end + insert << " WHERE NOT EXISTS (SELECT 1 FROM #{table_name} WHERE id=#{id});" end end