postgres SQL查询在节点JS中引发错误

时间:2019-05-29 14:48:48

标签: node.js postgresql express pgrouting

我设置了一个API,客户端用户可以在该API上计算点之间的路线。但是,我在psql查询中遇到了麻烦,该查询在postgres中有效,但是当我在节点JS中使用相同的查询时,我得到了一个错误。

我正在使用nodeJS,Express和Postgres。如果我在pgAdmin4中运行以下查询,则会得到预期的输出。

example_data %>%
 add_count(group) %>%
 slice(which(dense_rank(desc(n)) <= 2)) %>%
 select(-n)

但是当我在Node Js中使用相同的查询时(见下文),我收到一条错误消息,内容为SELECT b.gid, b.the_geom, b.cost_s, b.length_m FROM pgr_dijkstra('SELECT gid::bigint as id, source::bigint, target::bigint, cost_s::double precision as cost, reverse_cost_s::double precision as reverse_cost FROM ways WHERE the_geom && ST_Expand((SELECT ST_Collect(the_geom) FROM ways_vertices_pgr WHERE id IN(589143, 581050)), 0.01)', 589143, 581050) a LEFT JOIN ways b ON (a.edge = b.gid); 。我在做什么错了?

error: syntax error at or near "&&"

1 个答案:

答案 0 :(得分:0)

得到答案。我使用start语法而不是end$1,而是添加了参数的数据类型。就我而言,ineteger

SELECT b.gid, b.the_geom, b.cost_s, b.length_m FROM pgr_dijkstra('SELECT gid::bigint as id, source::bigint, 
                                           target::bigint, cost_s::double precision as cost, 
                                           reverse_cost_s::double precision as reverse_cost FROM ways 
                                           WHERE the_geom && ST_Expand((SELECT ST_Collect(the_geom) 
                                           FROM ways_vertices_pgr WHERE id IN(' || $1::integer || ',' || $2::integer ||')), 0.01)', 
    $1::integer, $2::integer) a LEFT JOIN ways b ON (a.edge = b.gid);