Following examples are based on messages in fb-devel, Vol 186, Issue 18 (date: 11-oct-2021).
Example #1.
set heading off;
set sqlda_display on;
select -(-32768) as n from rdb$database;
01: sqltype: 496 LONG scale: 0 subtype: 0 len: 4
...
32768
No error.
This means that rule from SQL:2016 which was mentioned by Mark:
"rule 2 establishes that the type of a negation is the type of the negated expression" - is broken here. Type of negation must remain smallint and thus negation of -32768 should raise exception.
Example #2.
select -(-2147483648) as n from rdb$database;
01: sqltype: 580 INT64 scale: 0 subtype: 0 len: 8
...
Statement failed, SQLSTATE = 22003
Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.
This result looks also not clear:
- why type of least possible integer value changed from INT to BIGINT ?
- why negation of this BIGINT value (though it is only 2^31, i.e. must less than limit for bigint) raises exception ?
/* Dmitry replied me privately about this and now I understand the reason: generating of BLR forces this value to "go back" to INT type. */
Shortly speaking, both examples must behave like this:
select -(-9223372036854775808) as n from rdb$database;
01: sqltype: 580 INT64 scale: 0 subtype: 0 len: 8
...
Statement failed, SQLSTATE = 22003
Integer overflow. The result of an integer operation caused the most significant bit of the result to carry.
(i.e. produce exception and do not change type of argument that is subject for negation).
Following examples are based on messages in fb-devel, Vol 186, Issue 18 (date: 11-oct-2021).
Example #1.
No error.
This means that rule from SQL:2016 which was mentioned by Mark:
"rule 2 establishes that the type of a negation is the type of the negated expression" - is broken here. Type of negation must remain smallint and thus negation of -32768 should raise exception.
Example #2.
This result looks also not clear:
/* Dmitry replied me privately about this and now I understand the reason: generating of BLR forces this value to "go back" to INT type. */
Shortly speaking, both examples must behave like this:
(i.e. produce exception and do not change type of argument that is subject for negation).