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

354
Views
How do I update json data in postgres sql in nodejs?

my data structure schema is like

users(
  id serial primary key,
  data json
);

I want to update data key.

I'm using node-postgres library and So far I have tried something like this:

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!! ");
        }
    });
});

this is not working, I'm getting error invalid input syntax for type json

Can anyone help, Thanks.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

So it was a syntax error, All I had to do stringfy json data and put that in 'quotes'

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!