* [multiplication]

All functions > MATH > *** [multiplication]**

Returns the product of two numbers, or scales an interval by an integer factor.

Syntax

left * right  ·  MULTIPLY(left, right)

Function form

Numeric multiplication: Product of the two numbers

MULTIPLY(number1: T, number2: T) → T
sql
ParameterTypeRequiredDescription
number1TYesFirst number to multiply
number2TYesSecond number to multiply

With:

  • T : Any numeric type

  • Both arguments must be of the same numeric type

  • Returns NULL if either operand is NULL

  • Multiplication is commutative: a * b = b * a

Interval scaling: The scaled interval

MULTIPLY(interval: INTERVAL, factor: T) → INTERVAL
sql
ParameterTypeRequiredDescription
intervalINTERVALYesInterval to scale
factorTYesInteger scale factor

With:

  • T : Integer type (TINYINT … BIGINT)

  • The factor is TINYINT, SMALLINT, INT, or BIGINT

  • Either operand order is accepted: interval * n or n * interval

  • Returns NULL if either operand is NULL

Returns: The scaled interval

MULTIPLY(factor: T, interval: INTERVAL) → INTERVAL
sql
ParameterTypeRequiredDescription
factorTYesInteger scale factor
intervalINTERVALYesInterval to scale

With:

  • T : Integer type (TINYINT … BIGINT)

Notes

  • Both operands must be compatible numeric types, or one must be INTERVAL and the other an integer
  • When scaling an interval, either order is accepted: interval * n or n * interval
  • Returns NULL if either operand is NULL
  • Multiplication is commutative
  • Very large finite magnitudes can overflow when using floating-point types

Examples

* — numeric

FeatureQL
RETURN
    -- Basic multiplication
    f1 := 3 * 4,
    -- Negative left operand
    f2 := -5 * 2
;
Result
f1 BIGINTf2 BIGINT
12-10

* — interval scaling

FeatureQL
RETURN
    -- Scale a day interval
    f1 := INTERVAL_PARSE('1 day') * 3,
    -- Integer on the left side
    f2 := 5 * INTERVAL_PARSE('2 hours')
;
Result
f1 VARCHARf2 VARCHAR
P3DPT10H

* — floating-point

FeatureQL
RETURN
    -- DOUBLE operands
    f1 := 1.5e0 * 3.0e0
;
Result
f1 DECIMAL
4.5

MULTIPLY(...)

FeatureQL
RETURN
    -- Function call
    f1 := MULTIPLY(3, 4)
;
Result
f1 BIGINT
12

.MULTIPLY(...) — chained

FeatureQL
RETURN
    -- Integer literal: parenthesize for `.MULTIPLY` on BIGINT
    f1 := (3).MULTIPLY(4),
    -- Decimal base: chain without extra parentheses
    f2 := 1.5.MULTIPLY(3)
;
Result
f1 BIGINTf2 DECIMAL
124.5

MULTIPLY — Interval scaling

FeatureQL
RETURN
    -- Scale a day interval
    f1 := INTERVAL_PARSE('1 day') * 3,
    -- Integer on the left side
    f2 := 5 * INTERVAL_PARSE('2 hours'),
    -- Compose sub-hour intervals
    f3 := INTERVAL_PARSE('15 minutes') * 4,
    -- Zero factor yields zero interval
    f4 := INTERVAL_PARSE('1 hour') * 0
;
Result
f1 VARCHARf2 VARCHARf3 VARCHARf4 VARCHAR
P3DPT10HPT1HPT0S

MULTIPLY — Edge cases

FeatureQL
RETURN
    -- Negative factor
    f1 := MULTIPLY(-5, 2),
    -- Multiplication by zero
    f2 := MULTIPLY(0, 100),
    -- DECIMAL × DECIMAL
    f3 := MULTIPLY(1.5, 3.0),
    -- DOUBLE × DOUBLE
    f4 := MULTIPLY(1.5e0, 3.0e0)
;
Result
f1 BIGINTf2 BIGINTf3 DECIMALf4 DECIMAL
-1004.54.5