Skip to content
Advertisement

InfluxDB placeholder “Empty bound parameter”

I’m struggling to format a InfluxDB query using placeholders.

Here I query with multiple placeholders. The values are defined in the placeholders object, as seen below,

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 });

Once sent, an error 400 - error parsing query: empty bound parameter

In the error I can see the GET request, where it appears that the Influx library has correctly formatted the placeholders under “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=&params={"from":"now()","interval":"5h","label":"person"}

How do I correctly format my query?

Advertisement

Answer

Have you tried changing

let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $<label> and time >= $<from> - $<interval>`;

TO

let query = `SELECT grid_ref_x, grid_ref_y, label FROM position
WHERE "label" = $label and time >= $from - $interval`;

The difference is that you reference the Placeholders or bind parameters using $variable_name instead of $<variable_name>. Assuming you’re using node_influx, you can remove the double quotes on your tags and it’ll still work.

I used this PR as reference https://github.com/node-influx/node-influx/issues/587

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement