I am using node-mysql
to update a MySQL database table from node.js. I want to update the timestamp column of a row with CURRENT_TIMESTAMP
. However, no changes seem to be made by node.js using the following code:
Node.js Code
client.query('UPDATE listings SET job_checkout_timestamp = CURRENT_TIMESTAMP WHERE listing_id = 1515');
But works if I were to replace CURRENT_TIMESTAMP
with a javascript time function, like new Date()
client.query('UPDATE listings SET job_checkout_timestamp = ? WHERE listing_id = 1515', [ new Date() ]);
However, if I were to execute the same SQL query directly into mysql (using Navicat), the row gets updated with the current timestamp!
Direct SQL Query
UPDATE listings SET job_checkout_timestamp = CURRENT_TIMESTAMP WHERE listing_id = 1515;
Did something go wrong somewhere?
It seems that node.js might convert the input variables into string,
and make the current_timestamp as string rather than mysql variables,
by replace the current_timestamp to synonym function call like :-
now()
current_timestamp()
should fix the problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With