我有一个奇怪的问题,我创建了一个基于this suggestion的自定义SQL函数。我有一个控制器动作create
模型Route
调用模型上的PG :: UndefinedFunction:ERROR:函数get_nearest_vertex_to_lon_lat(双精度,双精度)不存在
def get_route(startx, starty, endx, endy)
query = "SELECT seq, cost, slope::double precision, designacao::character varying(192), length::double precision," +
"ST_AsGeoJSON(geom) FROM pgr_dijkstra('" +
"SELECT gid AS id," +
"source::integer," +
"target::integer," +
"length AS cost " +
"FROM ways WHERE CAST(classif as int) <> 2'," +
"get_nearest_vertex_to_lon_lat(CAST(#{startx} as float) , CAST(#{starty} as float)), " +
"get_nearest_vertex_to_lon_lat(CAST(#{endx} as float), CAST(#{endy} as float)), false, false) a LEFT JOIN ways b ON (a.id2 = b.gid);"
results = ActiveRecord::Base.connection.execute(query)
return results
end
这部作品的发展,而且对生产不起作用这种方法,它提供了一个 PG::UndefinedFunction: ERROR: function get_nearest_vertex_to_lon_lat(double precision, double precision) does not exist
也 ActiveRecord::StatementInvalid (PG::UndefinedFunction: ERROR: function get_nearest_vertex_to_lon_lat(double precision, double precision) does not exist
奇怪的是我在postgres上执行这个查询,它的工作原理。