Mismatch in Date precision causes odd behavior
See original GitHub issueThe PostgreSQL TIMESTAMP type has a maximum precision of 1 microsecond, but the JavaScript Date type only has a maximum precision of 1 millisecond. This causes information to be silently discarded, leading to bizarre behavior:
client.query("SELECT '2017-01-01 00:00:00.00001'::timestamp as d", (err, res) => {
let date = res.rows[0].d;
client.query("SELECT '2017-01-01 00:00:00.00001'::timestamp = $1 as eq,\
'2017-01-01 00:00:00.00001'::timestamp > $1 as gt", [date], (err, res) => {
console.log(res.rows[0].eq); //false
console.log(res.rows[0].gt); //true
});
});
I’m not sure this a bug that could be fixed without using a non-standard Date object, but even if it isn’t fixed it should be at least noted in the documentation.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
The Model Performance Mismatch Problem (and what to do ...
After reading this post, you will know: The problem of model performance mismatch that may occur when evaluating machine learning algorithms.
Read more >Why does Date.parse give incorrect results? - Stack Overflow
The value will be different in different time zones. This behaviour is specified in ECMA-262 so all browsers do it the same way....
Read more >Is FindRoot wrong about its WorkingPrecision?
I noticed an odd mismatch between the behaviors of NDSolve and FindRoot. If you give NDSolve an equation of a certain precision, say...
Read more >MANAGING MISMATCH BETWEEN BELIEF AND BEHAVIOR
Her statements about racial equality do not express beliefs of hers, and we need some other story to explain why she makes those...
Read more >WEIRD bodies: mismatch, medicine and missing diversity
Evolution and Human Behavior ... WEIRD bodies: mismatch, medicine and missing diversity ... Next we discuss evolutionary mismatch, reaction norms and ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

For what it’s worth, I probably wasted about 60 hours last week, and cause a lot of pain to users, because there wasn’t a sentence about this in the main README.md page. I did systematically read through the fine README before starting to use the driver, and if there was a warning about timestamps silently rounding by “textually deleting the last 3 digits” instead of rounding, it would have helped. (And other than this, I really like this driver!)
I think the behavior of the driver is perhaps more surprising than your examples above suggest. What happens with the driver is completely different than what happens using postgresql’s
::timestamp(3)explicit cast, which rounds to the nearest timestamp, rather than just textually removing the last 3 digits.JavaScript doesn’t support microseconds, so wouldn’t this be self-implying for a JavaScript library?
No point documenting the obvious, imo.
And there is nothing bizarre in your example, because:
which makes the rest logically apparent: