On 11-10-2021 07:43, Kovalenko Dmitry wrote:
   The question is whether result of negation should keep the type of
source or can it be expanded if needed.

Then it would need to expand for all types.

And what would be an -INT128?

Result type must be same as result of expression "0-source"?

No, it is not. The SQL:2016 standards, section 6.29 <numeric value expression> says:

"""
Format

<numeric value expression> ::=
    <term>
  | <numeric value expression> <plus sign> <term>
  | <numeric value expression> <minus sign> <term>

<term> ::=
    <factor>
  | <term> <asterisk> <factor>
  | <term> <solidus> <factor>

<factor> ::=
  [ <sign> ] <numeric primary>

<numeric primary> ::=
    <value expression primary>
  | <numeric value function>

Syntax Rules
1) Case:
[..]
c) Otherwise, the declared type of both operands of a dyadic arithmetic operator is exact numeric and the declared type of the result is an implementation-defined exact numeric type, with precision and
scale determined as follows:
i) Let S1 and S2 be the scale of the first and second operands respectively. ii) The precision of the result of addition and subtraction is implementation-defined, and the scale is the maximum of S1 and S2.
[..]
2) The declared type of a <factor> is that of the immediately contained <numeric primary>.
"""

Rule 1 establishes that the result of addition and subtraction has an exact numeric type with implementation defined precision, while rule 2 establishes that the type of a negation is the type of the negated expression.

In other words -(smallintvalue) must be a SMALLINT, while 0 - (smaillintvalue) can an implementation defined exact numeric type with implementation defined precision (BIGINT in the case of dialect 3).

Note that in Dialect 1:

0-smallint -> integer
0-integer -> double

Behaviour for dialect 1 can be ignored, because dialect 1 has been deprecated for 20+ years.

In dialect 3, subtraction between SMALLINT, INTEGER and BIGINT all results in BIGINT.

Mark
--
Mark Rotteveel


Firebird-Devel mailing list, web interface at 
https://lists.sourceforge.net/lists/listinfo/firebird-devel

Reply via email to