Recently, I developed a feature to save and fetch points(lat and lon) from DB. It is working fine on my local, but on production database it is giving error:
PG::UndefinedFunction: ERROR: operator does not exist: point = unknown
LINE 1: ...s"."name" = '九龍灣' AND "region_points"."lonlat" = 'POINT(1...
^
HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts.
: SELECT COUNT(*) FROM "region_points" WHERE "region_points"."name" = '九龍灣' AND "region_points"."lonlat" = 'POINT(114.20910358428955 22.321574434895677)'
I digged into psql and found that there is difference in type for the columns.
On production:
production=> \d region_points
Table "public.region_points"
Column | Type | Modifiers
------------+-----------------------------+------------------------------------------------------------
id | integer | not null default nextval('region_points_id_seq'::regclass)
name | character varying(255) |
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
lonlat | point |
Indexes:
"region_points_pkey" PRIMARY KEY, btree (id)
"index_region_points_on_lonlat" gist (lonlat)
Whereas, type of lonlat on my local machine is: geography(Point,4326)
development=# \d region_points;
Table "public.region_points"
Column | Type | Modifiers
------------+-----------------------------+------------------------------------------------------------
id | integer | not null default nextval('region_points_id_seq'::regclass)
name | character varying(255) |
created_at | timestamp without time zone |
updated_at | timestamp without time zone |
lonlat | geography(Point,4326) |
Indexes:
"region_points_pkey" PRIMARY KEY, btree (id)
"index_region_points_on_lonlat" gist (lonlat)
My questions are:
- Is type wrong on my local or on production DB?
- How can I fix this?
- What is the difference between
pointandgeography(Point,4326)?
I checked postgis_full_version on local and production DB's. Here are the outputs:
Production:
POSTGIS="2.1.4 r12966" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.7.1, 23 September 2009" GDAL="GDAL 1.9.0, released 2011/12/29" LIBXML="2.7.8" LIBJSON="UNKNOWN" (core procs from "2.1.5 r13152" need upgrade) RASTER (raster procs from "2.1.5 r13152" need upgrade)
Development(local):
POSTGIS="2.1.5 r13152" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.10.1, released 2013/08/26" LIBXML="2.9.1" LIBJSON="UNKNOWN" RASTER
Is the error because of different versions?
