0

I am new to node-postgres and I want to insert a row in a table using node-postgres, where one column value is an array of strings and one an array of integers.

Earlier I used to use sequelize and now I am not using any ORMS, want to use the native library for postgres in Node.

let names =['abc', 'qwe', 'aaa'];
let type = [2, 3, 4, 5];

let query = 'INSERT INTO  sample(names, type) VALUES ($1, $2)' ;
db.query(query, [names, type], (err, res) => {
   if (err) {
   return (err)
 }
 return res.send(res.rows[0])
})

I am thrown an error invalid syntax near "["

7
  • You want raw query ? Commented Apr 16, 2019 at 10:00
  • @RameshS yes, I want a raw query using stored proceudres/parameterized query Commented Apr 16, 2019 at 10:01
  • Use sequelize ORM it is better then raw query Commented Apr 16, 2019 at 10:02
  • If these are text fields, you can do JSON.stringify and store the output. If I understood your question correctly... Commented Apr 16, 2019 at 10:04
  • 1
    if you are using raw query then make it as per insert format stackoverflow.com/questions/34990186/… Commented Apr 16, 2019 at 10:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.