datetime_add(t, a + b, "day") generates the SQL a + b || ' day'. Because || binds tighter than +, this is not the desired SQL, and always evaluates to NULL. Instead, it should be (a + b) || ' day'. Likewise, perhaps worse, datetime_add(t, a + b, "week") adds (a + b * 7), not (a + b) * 7, days, and similarly for datetime_add(t, a + b, "millisecond").
(date_add also has these issues.)
While investigating the above, I found some additional, though lesser, precedence issues:
is_nil(x and y) becomes x AND y IS NULL (should be (x AND y) IS NULL), is_nil(not x) becomes NOT (x) IS NULL (should be (NOT x) IS NULL), (not x) < y becomes NOT (x) < y (should be (NOT x) < y), and likewise with (not x) in [...] and x == (y in [...]) (becomes x = y IN (...), and = binds tighter than IN).
Also, within update, inc: [x: a + b] has a minor precedence bug that only matters when addition is non-associative (e.g. floating point, or integer overflow.) It becomes UPDATE ... SET x = x + a + b, which means x = (x + a) + b, but it should instead be x = x + (a + b).
datetime_add(t, a + b, "day")generates the SQLa + b || ' day'. Because||binds tighter than+, this is not the desired SQL, and always evaluates to NULL. Instead, it should be(a + b) || ' day'. Likewise, perhaps worse,datetime_add(t, a + b, "week")adds(a + b * 7), not(a + b) * 7, days, and similarly fordatetime_add(t, a + b, "millisecond").(
date_addalso has these issues.)While investigating the above, I found some additional, though lesser, precedence issues:
is_nil(x and y)becomesx AND y IS NULL(should be(x AND y) IS NULL),is_nil(not x)becomesNOT (x) IS NULL(should be(NOT x) IS NULL),(not x) < ybecomesNOT (x) < y(should be(NOT x) < y), and likewise with(not x) in [...]andx == (y in [...])(becomesx = y IN (...), and=binds tighter thanIN).Also, within
update,inc: [x: a + b]has a minor precedence bug that only matters when addition is non-associative (e.g. floating point, or integer overflow.) It becomesUPDATE ... SET x = x + a + b, which meansx = (x + a) + b, but it should instead bex = x + (a + b).