question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update not actually updating data

See original GitHub issue

Hi,

I’m executing an update on a row in my ‘field’ table where the type was previously ‘2’:

    return this.knex.table('field')
        .where({id : 1 })
        .update({type : 3})
        .returning('*')

This call does not fail, but the return shows that the type is STILL 2 and querying postgres shows that is in in fact still 2. Other calls, such as insert, are working fine.

Furthermore, I added a .toQuery() and copied and pasted the query directly to my database, and that worked (type was updated to 3).

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

5reactions
tgriessercommented, Jun 20, 2016

So this is something that will probably be addressed before 1.0 (at least with a warning), but queries aren’t actually executed until something triggers the promise (calling .then, .catch, etc. or another associated method).

If you put a .then() at the end of the .returning('*') does the query run? If that’s not the issue is there any chance you’re in a transaction that isn’t being committed?

2reactions
elhigucommented, Jul 8, 2019

Yep, documentation page doesn’t execute queries, but only prints out SQL that is generated by the query.

Anyhow nowadays preferred method to trigger query builder is to do

const res = await knex('table').where(A).update(B);
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is my update query not actually updating? - Stack Overflow
Based on your comment, you have JOIN on the wrong column. Here is the fix. UPDATE x SET x.sheet_expedient=db_data.sheet_expedient FROM ...
Read more >
sql server - UPDATE performance where no data changes
If I have an UPDATE statement that does not actually change any data (because the data is already in the updated state), is...
Read more >
update() function not actually updating record - ServiceNow
The problem is the update() function is not actually updating the record. According to the SN Docs site, Update() will return the sys_id...
Read more >
Data Sources Refreshing but Workbook Not Updating
I currently have the online sync client refreshing my data source every morning. It is updating successfully and even showing that the published...
Read more >
Data Refresh not updating table - Microsoft Power BI Community
try the follow: ` 1) check all the table queries, go to properties and be sure all have the update on refresh option...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found