Expression types

An expression has both a value and a type, type being a set of limits that the value must fall within. The following rules make use of EGL primitive types; see Primitive data types.

The following rules determine the type of an expression. These rules do not cover the possible conversion (promotion) of individual operands, which is platform-dependent:
Numeric expressions
These rules apply to expressions involving arithmetic operators. The rules define the expected type of the expression independent of precision or length, and do not state how operands are converted, as this process is different for each target language. The following binary operators can require promotion of one or more operands:
  • Arithmetic operators +, -, *, /, %, **
  • Numeric comparison operators ==, !=, <, >, <=, >=
  • Bitwise operators &, |, ^
The following rules apply, in order, to the arithmetic and numeric comparison operators:
  • If either operand is a text type, the type of the expression is NUMBER
  • Otherwise if either operand is a FLOAT, the type of the expression is FLOAT
  • Otherwise if either operand is a SMALLFLOAT the type of the expression is SMALLFLOAT
  • Otherwise if either operand is a NUM the type of the expression is NUM
  • Otherwise if either operand is a NUMC the type of the expression is NUMC
  • Otherwise if either operand is a DECIMAL the type of the expression is DECIMAL
  • Otherwise if either operand is a BIN the type of the expression is BIN
  • Otherwise if either operand is a BIGINT the type of the expression is BIGINT
  • Otherwise if either operand is an INT the type of the expression is INT
  • Otherwise if either operand is a SMALLINT the type of the expression is SMALLINT

Each of the bitwise operators and (&) , or (|), and exclusive or (^) perform a bitwise operation on two operands, returning a value of type INT. Either operand may be of type HEX(2), HEX(4), HEX(8), INT, or SMALLINT. The operation begins by converting any HEX or SMALLINT operand to type INT. In the case of HEX, the operation left-pads the operand's value with zeros until the length is 4 bytes.

Text expressions
These rules apply to operands of binary operations that must have text type values. The assumption here is that neither operand is a numeric type as then the rules for numeric expressions apply. The following text comparison operators can require promotion of one or more operands: ==, !=, <, >, <=, >=.
The following rules apply, in order:
  • If either operand is a STRING, the other is converted to STRING
  • Otherwise if either operand is STRING(i), the second is converted to STRING(j), where j is the larger of the length of the second operand and i.
  • Otherwise if either operand is UNICODE(i), the second is converted to UNICODE(j), where j is the larger of the length of the second operand and i.
  • Otherwise if either operand is MBCHAR(i), the second is converted to MBCHAR(j), where j is the larger of the length of the second operand and i.
  • Otherwise if either operand is CHAR(i), the second is converted to CHAR(j), where j is the larger of the length of the second operand and i.

Feedback