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

264
Views
Almacenamiento de objetos JSON en postgreSQL mediante consulta parametrizada

Tengo problemas para guardar objetos JSON en la base de datos mediante consultas parametrizadas. Estoy usando cartero para enviar este objeto en red.body ingrese la descripción de la imagen aquí

En mi lado del servidor tengo su código:

 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.'}, }) })

¿Por qué sigo recibiendo este error? Ingrese la descripción de la imagen aquí .

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

Aquí está mi esquema de tabla:

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

¿Cómo formateo $ 1 correctamente para que lo acepte como archivo JSON?

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

0

Ejemplo de consulta:

 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!