Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

260
Views
Storing JSON objects in the postgreSQL using parameterized query

I am having problems with saving JSON objects in the database using parameterized queries. I am using postman to send this object on red.body enter image description here

On my server side I havet his code:

queryController.createQuery = (req, res, next) => {
  const { info }= req.body;
  const sqlQuery = 'INSERT INTO test (info) VALUES ($1) RETURNING *';
  db.query(sqlQuery, [info])
  .then(result => {
    console.log(result);
    if (result) res.locals.message = "Saved the query successfully";
    next();
  })
  .catch(err => {
    return next({
      log: `queryController.createQuery: ERROR: ${typeof err === 'object' ? JSON.stringify(err) : err}`,
      message: { err: 'Error occurred in queryController.createQuery. Check server log for more details.'},
    })
  })

Why is that I still get this error: enter image description here

throw new TypeError('Client was passed a null or undefined query')
      ^

TypeError: Client was passed a null or undefined query

Here is my table schema:

CREATE TABLE test (
    id serial NOT NULL PRIMARY KEY,
    info json NOT NULL
);

How do I format $1 correctly to get it accept it as JSON file?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Query example:

EXECUTE 'INSERT INTO test (info) VALUES ($1) RETURNING *' USING '[{"size": "Small", "quantity": 1, "product_id": 1}]'::jsonb;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!