W
W
WhatIsHTML2018-04-30 19:27:44
PostgreSQL
WhatIsHTML, 2018-04-30 19:27:44

SELECT NOT IN syntax error?

I am using pg-promise for nodejs .
It is necessary to make a selection according to the NOT IN condition. In the example, the parameter that comes in is an array.
https://github.com/vitaly-t/pg-promise/wiki/Learn-...
I have this view object

let obj = {
    limit: limit,
    list: list // массив здесь
  };

The request itself:
return db.query(`
            SELECT *
            FROM table WHERE 
            id NOT IN (${obj.list}:csv)
            LIMIT ${obj.limit}
        `);

An error is thrown
{ error: ошибка синтаксиса (примерное положение: ":")

1. What am I doing wrong?
2. How to correctly substitute parameters in the request so that all potentially dangerous characters are escaped? Am I correct or not?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2018-04-30
@WhatIsHTML

What am I doing wrong?

Trying to substitute values ​​using template strings instead of using the formatting tools that pg-promise provides (or rather, mixing these approaches).
Yes, something like this, for example:
db.query(`
  SELECT *
  FROM table
  WHERE id NOT IN ($(list:csv))
  LIMIT $(limit)
`, obj)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question