From bdc8c18070a783b57acd4ba1ca23fc8e0109f62a Mon Sep 17 00:00:00 2001
From: Jev Zelenkov <jev@jz.ee>
Date: Sat, 18 Oct 2014 01:24:52 +0200
Subject: [PATCH] Fixes OID warnings when using PostgreSQL

Postgres correctly identifies OIDs when BEARING and DISTANCE contain
numerical values. It fails to identify OID for a NULL type.

This patch explicitly sets an OID type for NULLs when running in
PostgreSQL environment.
---
 lib/geocoder/stores/active_record.rb | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/geocoder/stores/active_record.rb b/lib/geocoder/stores/active_record.rb
index 91fabe05..dbadd213 100644
--- a/lib/geocoder/stores/active_record.rb
+++ b/lib/geocoder/stores/active_record.rb
@@ -45,7 +45,8 @@ module Geocoder::Store
             # If no lat/lon given we don't want any results, but we still
             # need distance and bearing columns so you can add, for example:
             # .order("distance")
-            select(select_clause(nil, "NULL", "NULL")).where(false_condition)
+            null_val = using_postgres? ? 'NULL::text' : 'NULL'
+            select(select_clause(nil, null_val, null_val)).where(false_condition)
           end
         }
 
@@ -64,7 +65,8 @@ module Geocoder::Store
               full_column_name(geocoder_options[:longitude])
             ))
           else
-            select(select_clause(nil, "NULL", "NULL")).where(false_condition)
+            null_val = using_postgres? ? 'NULL::text' : 'NULL'
+            select(select_clause(nil, null_val, null_val)).where(false_condition)
           end
         }
       end
@@ -224,6 +226,10 @@ module Geocoder::Store
         connection.adapter_name.match(/sqlite/i)
       end
 
+      def using_postgres?
+        connection.adapter_name.match(/postgres/i)
+      end
+
       ##
       # Value which can be passed to where() to produce no results.
       #
-- 
GitLab