multiply
Use the multiply() function to calculate the product of two numbers.
Syntax
multiply (<string> | <integer> | <float>, <string> | <integer> | <float>)Parameters
value_1
integer, float, string
Yes
The first numeric value.
value_2
integer, float, string
Yes
The second numeric value.
Returns
The multiply() function returns the numerical product of the two input numbers.
Usage notes
The function accepts various numeric inputs, including numeric literals (for example, 2, 1.5), floating-point numbers, and integers.
The function also accepts integers or numbers provided as a string type (for example, extracted from a data field and then converted).
The function supports negative numbers for both input parameters.
Examples
Example 1: Multiply integer field by integer literal
Goal: Demonstrate multiply() applied directly to an integer field (event_id) and a fixed integer literal.
XQL code:
Explanation: This query creates a new field, multiplied_event_id, by taking each event_id (for example, 101) and multiplying it by 2.
Output:
101
202
102
204
103
206
Example 2: Multiply floating-point field by integer literal
Goal: Showcase multiply() with a floating-point input field (duration_seconds) and an integer literal.
XQL code:
Explanation: Here, duration_seconds (which contains decimal values, for example, 1.5, 0.8) is multiplied by 10, producing a new floating-point value in multiplied_duration.
Output:
101
1.5
15.0
102
0.8
8.0
103
10.2
102.0
Example 3: Multiply floating-point field by floating-point literal
Goal: Demonstrate multiply() handling two floating-point numbers, including a decimal literal.
XQL code:
Explanation: This query multiplies duration_seconds by 0.75, resulting in precise_duration_calc, which will also be a floating-point number.
Output:
101
1.5
1.125
102
0.8
0.6
103
10.2
7.65
Example 4: Multiply with a negative integer literal
Goal: Demonstrate multiply() handling a negative input, producing a negative result.
XQL code:
Explanation: The event_id is multiplied by -1. This correctly computes the negative product, demonstrating the function's behavior with negative inputs.
Output:
101
-101
102
-102
103
-103
Example 5: Multiply string-converted-to-number field by integer literal
Goal: Show multiply() applied to a numeric value extracted from a JSON field and converted from a string, demonstrating flexibility with input types.
XQL code:
Explanation: This query first extracts a numeric value (either code or size_gb) from the simple_json_data field as a string. The query then converts this string to a number using to_number() and applies multiply() with a literal, storing the result in multiplied_json_value.
Output:
101
{"status": "ok", "code": 200}
200
600
110
{"backup_id": "DB-005", "size_gb": 500}
500
1500
Related articles
Stages:
alter
Last updated
Was this helpful?
