PG :: UndefinedFunction:ERROR:函数get_nearest_vertex_to_lon_lat(双精度,双精度)不存在

时间:2015-10-29 19:45:44

标签: ruby-on-rails postgresql rails-activerecord postgis pg

我遇到了一个奇怪的问题,我创建了一个基于this suggestion的自定义SQL函数。我有一个模型Route,其控制器操作create可以在模型上调用此方法

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上执行此查询并且它有效。

1 个答案:

答案 0 :(得分:0)

事实证明,尽管我的配置database.yml用于制作,但我并不知道Heroku创建了自己的生产数据库,因此显然不知道任何自定义sql函数,甚至表格。

为了将来参考,如果您要部署到heroku并且您正在使用远程数据库,则必须执行this first,然后设置自己的DATABASE_URL