InfluxDB 占位符 "Empty bound parameter"
InfluxDB placeholder "Empty bound parameter"
我正在努力使用占位符格式化 InfluxDB 查询。
这里我用多个占位符查询。
这些值在占位符对象中定义,如下所示,
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $<label> and time >= $<from> - $<interval>`;
const placeholders = {label: 'person', from: 'now()', interval: '5m'};
const resp = await influx.query(query, { placeholders });
发送后,error 400 - error parsing query: empty bound parameter
在错误中我可以看到 GET 请求,Influx 库似乎已正确格式化“params”下的占位符。
/query?p=root&u=root&db=heatmap&epoch=&q=SELECT grid_ref_x, grid_ref_y, label FROM position WHERE label = $<label> and time >= $<from> - $<interval>&rp=¶ms={"from":"now()","interval":"5h","label":"person"}
如何正确设置查询格式?
你尝试过改变
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $<label> and time >= $<from> - $<interval>`;
到
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $label and time >= $from - $interval`;
不同之处在于您使用 $variable_name 而不是 $[= 来引用占位符或绑定参数23=]。假设您使用的是 node_influx,您可以删除标签上的双引号,它仍然有效。
我用这个PR作为参考https://github.com/node-influx/node-influx/issues/587
我正在努力使用占位符格式化 InfluxDB 查询。
这里我用多个占位符查询。 这些值在占位符对象中定义,如下所示,
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $<label> and time >= $<from> - $<interval>`;
const placeholders = {label: 'person', from: 'now()', interval: '5m'};
const resp = await influx.query(query, { placeholders });
发送后,error 400 - error parsing query: empty bound parameter
在错误中我可以看到 GET 请求,Influx 库似乎已正确格式化“params”下的占位符。
/query?p=root&u=root&db=heatmap&epoch=&q=SELECT grid_ref_x, grid_ref_y, label FROM position WHERE label = $<label> and time >= $<from> - $<interval>&rp=¶ms={"from":"now()","interval":"5h","label":"person"}
如何正确设置查询格式?
你尝试过改变
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $<label> and time >= $<from> - $<interval>`;
到
let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $label and time >= $from - $interval`;
不同之处在于您使用 $variable_name 而不是 $
我用这个PR作为参考https://github.com/node-influx/node-influx/issues/587