unknown OID 18448: failed to recognize type of 'geom'. It will be treated as String.
Closed this issue · 4 comments
Given an PostGIS table with:
Table "public.mytable"
Column | Type | Modifiers
------------+-----------------------------+--------------------------------------------------------
gid | integer | not null default nextval('mytable_gid_seq'::regclass)
geom | geometry(MultiPolygon,4326) |
And a record:
gid | geom
-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
22453 | 0106000020E610000001000000010300000001000000050000004D41CAF9367E52C0ECC08812396444406ED825FC397E52C0698BB3DA306444401A4502053B7E52C0D826F3B9316444402CDBA602387E52C01F93C8F1396444404D41CAF9367E52C0ECC0881239644440
And an ActiveRecord object:
class Record < ActiveRecord::Base
self.table_name = 'mytable'
end
Querying for the object yields a warning unknown OID 18448: failed to recognize type of 'geom'. It will be treated as String.
and returns the geom
field as a string instead of an MultiPolygon:
puts Record.first.geom
# 0106000020E610000001000000010300000001000000050000004D41CAF9367E52C0ECC08812396444406ED825FC397E52C0698BB3DA306444401A4502053B7E52C0D826F3B9316444402CDBA602387E52C01F93C8F1396444404D41CAF9367E52C0ECC0881239644440
=> nil
I don't quite understand why this adapter isn't deserializing my column from EWKB to my MultiPolygon. Using the same text and the RGeo::WKRep::WKBParser
, I can get the polygon back, eg:
RGeo::WKRep::WKBParser.new(nil, support_ewkb: true).parse(Record.first.geom)
# => #<RGeo::Cartesian::MultiPolygonImpl:0x16a54a4 "MULTIPOLYGON (((-73.97210545302842 40.782991711401195, -73.97228912063449 40.78274091498208, -73.97235226842568 40.78276752827304, -73.97216860098405 40.783018324791776, -73.97210545302842 40.782991711401195)))">
How does one get this field to deserialize automatically? Or is this a bug?
I added some tests in #243 & could not reproduce this. Can you create a failing test?
I'll give it a shot; it's going to take some time to write.
It's worth noting, this table was not created via the adapter/ActiveRecord migration, it's a raw table that was imported from shp
file. Given you're more experienced with AR and Postgres adapters, do you know where I might start looking to find where this OID is supposed to be? Or where this warning is raised? Is it a Postgres configuration? Table setting? Any suggestions might help me figure it out faster.
Okay, I found the issue. I was using ActiveRecord without Rails. So to connect to my DB, I was using connection URLs and establish_connection
instead of database.yml
. I thoughtmy connection string should look something like:
postgres://myuser@myhost:5432/mydb?pool=5&adapter=postgis
However, Rails was ignoring the adapter
parameter. To fix it, I had to change the connection string to look like:
postgis://myuser@myhost:5432/mydb?pool=5
Afterwards, it was auto-deserializing my geometry. So it's a misconfiguration on my part, not a problem with the gem. Sorry to bother you with this issue. At least if you see similar issues, you could suggest taking a harder look at their configuration.
Feel free to close this one. Thanks for following up!
Thanks for the follow-up.