aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--config/initializers/postgresql_adapter_patch.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/config/initializers/postgresql_adapter_patch.rb b/config/initializers/postgresql_adapter_patch.rb
index ae228f62f..6284c80ed 100644
--- a/config/initializers/postgresql_adapter_patch.rb
+++ b/config/initializers/postgresql_adapter_patch.rb
@@ -10,3 +10,28 @@
# end
# end
# ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::NATIVE_DATABASE_TYPES[:primary_key] = "bigserial primary key"
+
+# Add missing double-quote to write array of daterange in SQL query
+# See #1782
+
+class ActiveRecord::ConnectionAdapters::PostgreSQLColumn
+
+ def self.array_to_string(value, column, adapter)
+ casted_values = value.map do |val|
+ if String === val
+ if val == "NULL"
+ "\"#{val}\""
+ else
+ quote_and_escape(adapter.type_cast(val, column, true))
+ end
+ elsif Range === val
+ casted_value = adapter.type_cast(val, column, true)
+ "\"#{casted_value}\""
+ else
+ adapter.type_cast(val, column, true)
+ end
+ end
+ "{#{casted_values.join(',')}}"
+ end
+
+end