【发布时间】:2017-01-12 08:30:21
【问题描述】:
我正在努力将 geoJSON 多边形数据插入 postgis 表。 PostGis 工作正常。我可以从 PG 客户端执行此查询,但它不适用于 rails 中的应用程序。
我在 rails 模型中的插入查询:
class Route < ActiveRecord::Base
def self.AddNew(id_partner, route_name, polygon, active)
sql = "INSERT INTO routes('idPartner', 'name', 'polygon', 'active') VALUES ('#{id_partner}', '#{route_name}', ST_GeomFromGeoJSON('#{polygon}'),4326), '#{active}')"
ActiveRecord::Base.connection.execute(sql)
end
end
我不断得到:
PG::SyntaxError: ERROR: syntax error at or near "'idPartner'" LINE 1: INSERT INTO routes('idPartner', 'name', 'polygon', 'active')... ^ : INSERT INTO routes('idPartner', 'name', 'polygon', 'active') VALUES ('8', 'Dara', ST_GeomFromGeoJSON('{"type":"POLYGON","id":null,"coordinates":[[[19.00634765625,52.736291655910925],[22.1484375,52.133488040771475],[22.236328125,52.8823912222619]]]}'),4326), '1')
表结构:
-- Table: public.routes
CREATE TABLE public.routes
(
id integer NOT NULL DEFAULT nextval('routes_id_seq'::regclass),
"idPartner" integer,
name character varying,
polygon geometry(Geometry,4326),
active integer,
CONSTRAINT routes_pkey PRIMARY KEY (id)
)
WITH (
OIDS=FALSE
);
ALTER TABLE public.routes
OWNER TO postgres;
有什么想法吗?
【问题讨论】:
标签: ruby-on-rails postgresql postgis