'SQL params in plv8 with dblink

I've run into a problem using $-params in plv8. I've pared things down to what seem to be the essential test cases:

plv8.elog(NOTICE, JSON.stringify(plv8.execute(`select $1`, [1])));

Returns [{"?column?":"1"}] as expected.

plv8.elog(NOTICE, JSON.stringify(plv8.execute(`select * from dblink('dbname=nebulacore', 'select 1') as t1(id integer)`)));

Returns [{"id":1}] as expected.

plv8.elog(NOTICE, JSON.stringify(plv8.execute(`select * from dblink('dbname=nebulacore', 'select $1') as t1(id integer)`, [1])));

Gets: ERROR: parameter numbers mismatch: 0 != 1

Is the problem in the third case that the $1 is inside a string inside the SQL? If so, is there a way around this, other than inlining the values directly? I want to use $-params for the sanitization benefit. Alternately, is there a plv8 or other function that will take an arbitrary value and return a sanitized one, which I can then inline if there's no way to get $-params to work here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source