database/sql: query("now() + ?", time.Hour) is surprising #46427
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
Today I learned two fun facts:
now()
is a datetime,now() + 0
is an integer formed from all of the decimal digits in the date. e.g. 2021-05-27 17:00:26 vs 20210527170026. (I'm not sure why one would ever want that.)database/sql
API for prepared statements, "?" applied to a duration value treats the duration (thanks to reflection on the underlying type) as an integer number of nanoseconds, not an interval. I don't know why one would ever want that either, since nanoseconds are not really useful in SQL.The combination of these two facts means that the behavior of
query("now() + ?", 1*time.Hour)
isn't remotely close to what one might expect:If database/sql were to treat durations specially, they could be mapped to
interval 1 hour
, avoiding this pitfall.The text was updated successfully, but these errors were encountered: