You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Potential hack for integer-safe addition in SQLite #253
SELECT9223372036854775807,
9223372036854775807+9223372036854775807, -- Casts to real and gives lossy result
typeof(9223372036854775807),
typeof(9223372036854775807+9223372036854775807);
SELECT
(SELECTSUM(x) FROM (SELECT9223372036854775807AS x UNION ALLSELECT9223372036854775807)); -- integer overflow error
Sum() will throw an "integer overflow" exception if all inputs are integers or NULL and an integer overflow occurs at any point during the computation.
I don't know what madness inspired me to come up with this workaround. I regret it now because I'm seriously considering this...
user-defined functions are more "elegant" but it means having to always create it, and the AST isn't technically portable unless the special bigint_add() function is added to every SQLite database you want to run the query on
Activity
AnyhowStep commentedon Feb 18, 2020
We are abusing an aggregate function, derived table, and compound query just to get integer overflow errors...
AnyhowStep commentedon Feb 18, 2020
I don't know what madness inspired me to come up with this workaround. I regret it now because I'm seriously considering this...
user-defined functions are more "elegant" but it means having to always create it, and the AST isn't technically portable unless the special
bigint_add()function is added to every SQLite database you want to run the query onAnyhowStep commentedon Feb 18, 2020
We want a throw-on-overflow addition operator, and not a cast-on-overflow operator, because of this,
This should throw.
But on SQLite, we get
1849668512354311.8It is decidedly not an integer.