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

356
Views
¿Cómo actualizo los datos json en postgres sql en nodejs?

mi esquema de estructura de datos es como

 users( id serial primary key, data json );

Quiero actualizar la clave de data .

Estoy usando la biblioteca node-postgres y hasta ahora he intentado algo como esto:

 pg.connect(process.env.DATABASE_URL, function(err, client, done) { var queryString = "UPDATE users SET data =" + myNewJsonData + " WHERE id = " + userIdToEdit + ";"; client.query(queryString, function(err, result) { done(); if (err) { res.send("Failed to update user data "); throw err; } else { res.send("Successfully updated user data!! "); } }); });

esto no funciona, recibo un error invalid input syntax for type json

¿Alguien puede ayudar? Gracias.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Así que fue un error de sintaxis, todo lo que tenía que hacer con los datos json de stringfy y poner eso entre 'comillas'

 pg.connect(process.env.DATABASE_URL, function(err, client, done) { var newJsonDataStringyfied = JSON.stringify(myNewJsonData) var queryString = "UPDATE users SET data = '" + newJsonDataStringyfied + "' WHERE id = " + userIdToEdit + ";"; client.query(queryString, function(err, result) { done(); if (err) { res.send("Failed to update user data "); throw err; } else { res.send("Successfully updated user data!! "); } }); });
about 4 years ago · Santiago Trujillo 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!