Reputation: 3165
I was trying to implement hacker news algorithm using mysql and got the following error
Double value is out of range in
pow(((unix_timestamp() - unix_timestamp(postDateTime))/3600 + 1),1.5)
Where the value of postDateTime is 2012-12-15 10:41:31
If i implement the above as
pow(((unix_timestamp() - unix_timestamp(cast(postDateTime as signed)))/3600 + 1),1.5)
Its working perfectly but i am not understanding the reason behind it
Upvotes: 0
Views: 2261
Reputation: 3470
What version of mysql are you running? Check this link out.
And check the documentation to understand why you are getting negative values:
If called with no argument, returns a Unix timestamp (seconds since '1970-01-01 00:00:00' UTC) as an unsigned integer. If UNIX_TIMESTAMP() is called with a date argument, it returns the value of the argument as seconds since '1970-01-01 00:00:00' UTC. date may be a DATE string, a DATETIME string, a TIMESTAMP, or a number in the format YYMMDD or YYYYMMDD. The server interprets date as a value in the current time zone and converts it to an internal value in UTC.
...
If you want to subtract UNIX_TIMESTAMP() columns, you might want to cast the result to signed integers. See Section 12.10, “Cast Functions and Operators”.
Upvotes: 1