to_string
Use the to_string() function to convert a non-string value (such as a number, float, or boolean) into its string representation.
Syntax
to_string (<field>)Parameters
field
integer, float, boolean
Yes
The field or literal value that you wish to convert to a string.
Returns
The to_string() function returns a string data type.
Usage notes
The function supports converting numerical types (integers and floats) and boolean values into strings.
If the input field or literal is
NULL, the function returnsNULL.This function is essential when a string input is required for other XQL functions (like
concat(),format_string(), orsplit()) or for performing string-based comparisons infilterstages.
Examples
Example 1: Converting a numeric (integer) field
Goal: Convert an integer field (event_id) to its string representation.
XQL code:
Explanation: The numeric event_id (for example, 101) is successfully converted by to_string() into the string "101".
Output:
101
"101"
102
"102"
103
"103"
Example 2: Converting a numeric (float) field
Goal: Convert a floating-point field (duration_seconds) to its string representation.
XQL code:
Explanation: The floating-point duration_seconds (for example, 1.5) is converted by to_string() into the string "1.5".
Output:
101
1.5
"1.5"
102
0.8
"0.8"
103
10.2
"10.2"
Example 3: Converting a boolean field
Goal: Convert a boolean field (is_successful) to its string representation.
XQL code:
Explanation: The boolean is_successful value (for example, true) is converted by to_string() into the string "true".
Output:
101
true
"true"
102
false
"false"
103
true
"true"
Example 4: Converting a literal numeric value
Goal: Convert a literal integer and a literal float to their string representations.
XQL code:
Explanation: Both the integer 99 and the float 3.14 are directly converted into their respective string representations.
Output:
101
"99"
"3.14"
102
"99"
"3.14"
103
"99"
"3.14"
Example 5: Using to_string() in a filter condition
Goal: Convert a field to a string to enable string-based comparison in a filter stage.
XQL code:
Explanation: The event_id field is converted to a string before being compared to the string literal "101", successfully filtering for the event with ID 101.
Output:
101
"User login successful"
true
Example 6: Handling NULL input field
Goal: Demonstrate the behavior when the input field is explicitly NULL.
XQL code:
Explanation: When the input to to_string() is NULL (for example, dst_domain for event ID 105), the function consistently returns NULL.
Output:
105
NULL
NULL
Related articles
Functions:
concat,format_string,split
Last updated
Was this helpful?
