long()
Converts a value to a 64-bit integer.
Syntax
long(EXPR)
Parameters
EXPR- The value or expression to convert to a 64-bit integer.
Description
The long() function converts the argument to a 64-bit integer (long) and returns it. If the argument is null, returns null. If conversion fails, also returns null.
Behavior by input type:
- Numeric: Calls
longValue()for conversion. Returnsnullfor a float or double outside the 64-bit integer range. - IPv4 address: Converts the 4 bytes to an unsigned integer. For example,
192.0.2.1returns3221225985. - String: Parsed as a decimal number. Returns
nullfor an empty string. - Array or list: The conversion is applied recursively to each element.
Only base 10 (decimal) is currently supported. Specifying a different base causes an error during the parsing phase.
Error codes
| Error code | Description |
|---|---|
| 90840 | A base other than 10 was specified. |
Usage examples
To prepare the WEB_APACHE_SAMPLE table used in these examples, refer to Preparing sample data.
-
Converting the
src_ipfield to a 64-bit integertable limit=5 WEB_APACHE_SAMPLE | eval result = long(src_ip) | fields src_ip, result | # result: the IP address converted to an unsigned integer -
Converting the
bytesfield to a 64-bit integertable limit=5 WEB_APACHE_SAMPLE | eval result = long(bytes) | fields bytes, result | # result: the same 64-bit integer value as the bytes field -
Non-convertible string
json "{'val': 'invalid'}" | eval result = long(val) | # result: null -
NULL input
json "{'val': null}" | eval result = long(val) | # result: null
Compatibility
The long() function has been available since before Sonar 4.0.