Replies: 1 comment
-
This probably mostly comes in as a question of where should implicit type conversion occur (if anywhere). Without implicit type conversion I would expect the above example to error.
Perhaps a special operation could exist which protects from overflows. If you were doubling the type for each addition, as you suggest, it would cause:
Realistically, one could simply use: a: u64, b: i64
CAST(a AS i128) + CAST(b AS i128) Maybe this could be aliased as Thoughts? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
sqlparser-rs version 16, has the capability to have unsigned integers. I'm wondering how we want to address arithmetic operations between signed and unsigned numbers? Or maybe a better question is how do we address out of range and overflow issues in gluesql?
Here is how mysql addresses these issues: out of range/overflow
Addressing my first question..
How should we handle the following:
let x:i8 = 127
let y:u8 = 128
x can contain any value between -127 and 127
y can contain any value between 0 and 255.
The result could contain any value between -127 and 382 which is outside the range for an i8 and an u8. Should we promote the result to an i16 (or i32, or i64),? If the result is being put into a table with a given datatype (maybe an i8), then let it complain if the result is out of range? What do you think?
It seems that currently in gluesql, when we do something like " select 2+125 from mytable", the 2 and 125 are treated as ints (i64), and if try to insert them into a column that is an i8, it gives the following error:
insert into myi8 select 2 + 125 from myi8;
[error] incompatible data type, data type: Int8, value: I64(
127,
)
For most things, this seems to work just fine. We can use the cast function to convert the result to an i8. I guess we could convert the i8 and u8 (from my example above) to i64? and then do the math?
for math between i64 and u64, we could convert both operands to an i128?
I guess for u128 or i128 and anything else just promote to i128 and hope for the best, and produce an error if an overflow occurs?
Billy
Beta Was this translation helpful? Give feedback.
All reactions