> ## Documentation Index
> Fetch the complete documentation index at: https://docs.kinetica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Expressions

*Kinetica* has native API support for a variety of expressions, which are used
as inputs while querying data *(for supported SQL expressions, see*
[Queries (SQL)](https://docs.kinetica.com/content/sql/query.md) *)*.  These native API expressions can involve one or
more constants (both numeric and string) and *table* columns. The expressions
follow certain constraints based on where they are used, but all the expressions
should follow the basic guidelines outlined below.

> [!NOTE]
>
> Use parentheses liberally to ensure correct order-of-operations.

## Constants

| Type | Details |
| - | - |
| String | String constants must be enclosed in single quotes or double quotes, e.g.,   \* 'hello'  \* "world" |
| Numerical | Numerical constants can be expressed as:   \* decimal integers (`31242`)  \* hex integers (`0x3420123a`)  \* doubles (`3.41e5`)  \* floats (`3.1415F`) |
| Date/Time | Supported date formats have optional leading zeros for months & days, while datetime optionally supports UTC format.  Examples of each date/time data type:   \* date     (`2000-1-2`, `2020-01-02`)  \* time     (`1:23:45`, `17:17:17`)  \* datetime (`2000-1-2 1:23:45.678`, `2020-01-02T17:17:17Z`) |

## Operators

When these operators are applied to numeric columns, they will interpret
non-zero values as *true* and zero values as *false*, returning `1` for *true*
and `0` for *false*.

| Type | Details |
| - | - |
| Bitwise | `&` `\|` `<<` `>>` `~` `^` |
| Comparison | `>` `<` `>=` `<=` `==` `=` `!=` `<>` `in` |
| Logical | `and`: Evaluates to *true* only if both sides of the expression are *true*; see [Short-Circuiting](https://docs.kinetica.com/content/concepts/expressions.md#short-circuiting) for error-checking details   `or`: Evaluates to *true* if either side of the expression is *true*; see [Short-Circuiting](https://docs.kinetica.com/content/concepts/expressions.md#short-circuiting) for error-checking details   `xor`: Evaluates to *true* only if one side of the expression is *true* and the other *false*   `not`: Evaluates to *true* if the expression is *false*, and vice versa   `!`: Synonym for `not` |
| Mathematical | `+` `-` `*` `/` |

## Functions

### Array Functions

#### Scalar Functions

> [accordion] ARRAY\_APPEND(array, value)
>
> Returns an array consisting of `array` with `value` appended to the end.

> [accordion] ARRAY\_CONCAT(arr1, arr2)
>
> Returns an array consisting of all the elements of array `arr1` followed by all of
> the elements of array `arr2`.

> [accordion] ARRAY\_CONTAINS(array, value)
>
> Returns true if `value` is present in `array`.

> [accordion] ARRAY\_CONTAINS\_ALL(arr1, arr2)
>
> Returns true if every value in array `arr2` is present in array `arr1`; otherwise
> returns false.

> [accordion] ARRAY\_CONTAINS\_ANY(arr1, arr2)
>
> Returns true if any value in array `arr2` is present in array `arr`; otherwise
> returns false.

> [accordion] ARRAY\_DISTINCT(array)
>
> Returns an array consisting of `array` values with duplicates removed.

> [accordion] ARRAY\_EMPTY(array)
>
> Returns true if `array` is empty; otherwise returns false.

> [accordion] ARRAY\_EXCEPT(arr1, arr2)
>
> Returns an array consisting of all of the elements of array `arr1` with the ones that
> also appear in array `arr2` removed.

> [accordion] ARRAY\_INTERSECT(arr1, arr2)
>
> Returns an array consisting of all of the elements of array `arr1` that also appear
> in array `arr2`.

> [accordion] ARRAY\_ITEM(array, pos)
>
> Returns the item in `array` at the given 1-based `pos` position.
>
> See [examples](https://docs.kinetica.com/content/concepts/array.md#array-func-ex-item).

> [accordion] ARRAY\_LENGTH(array)
>
> Returns the number of items in the given `array` at the 1st dimension.
>
> See [examples](https://docs.kinetica.com/content/concepts/array.md#array-func-ex-len).

> [accordion] ARRAY\_LOWER(array, dim)
>
> Returns the lowest index of `array` in the given `dim` dimension; since all arrays
> are 1-dimensional, only specifying a dimension of `1` will return a value, and since
> array indices are 1-based, that value will always be `1`.

> [accordion] ARRAY\_NDIMS(array)
>
> Returns the number of dimensions in the given `array`; since all arrays are
> 1-dimensional, that number will always be `1`.

> [accordion] ARRAY\_NOT\_EMPTY(array)
>
> Returns true if `array` is not empty; otherwise returns false.

> [accordion] ARRAY\_SLICE(array, from, to)
>
> Returns an array consisting of the values from `array` between the `from` index
> (inclusive) up to the `to` index (exclusive) using 0-based indexing. Negative indexes
> are treated as offsets from the end of the array.

> [accordion] ARRAY\_TO\_STRING(array, delim)
>
> Converts the items of `array` into a string delimited by `delim`.
>
> See [examples](https://docs.kinetica.com/content/concepts/array.md#array-func-ex-atos).

> [accordion] ARRAY\_UPPER(array, dim)
>
> Returns the highest index of `array` in the given `dim` dimension; since all arrays
> are 1-dimensional, only specifying a dimension of `1` will return a value, and since
> array indices are 1-based, that value will always be equivalent to `ARRAY_LENGTH`.

> [accordion] MAKE\_ARRAY(value)
>
> Returns an array consisting of the single `value` element.

> [accordion] STRING\_TO\_ARRAY(str, delim)
>
> Converts the values in `str`, delimited by `delim`, into an array.
>
> See [examples](https://docs.kinetica.com/content/concepts/array.md#array-func-ex-stoa).

#### Aggregation/Transposition Functions

The following functions can be used on [array](https://docs.kinetica.com/content/concepts/array.md)
columns within [aggregations](https://docs.kinetica.com/content/concepts/expressions.md#aggregate-expressions-label).

These functions can be used to convert primitive column values into arrays of
those values (aggregation) or to convert array columns into columns of primitive
values (unnest).

> [accordion] ARRAY\_AGG(expr)
>
> Combines column values within a group into a single *array* of those values.
>
> See [examples](https://docs.kinetica.com/content/concepts/array.md#array-func-agg-ex-agg).

> [accordion] ARRAY\_AGG\_DISTINCT(expr)
>
> Combines column values within a group into a single *array* of those values, removing
> any duplicates.
>
> See [examples](https://docs.kinetica.com/content/concepts/array.md#array-func-agg-ex-agg-dist).

> [accordion] UNNEST\_JSON\_ARRAY
>
> Transposes array values into columnar data.
>
> See [UNNEST\_JSON\_ARRAY](https://docs.kinetica.com/content/concepts/array.md#array-func-unnest).

### Conditional Functions

> [accordion] CASE(expr, \{\<matches>}, \{\<values>}, value\_if\_no\_match)
>
> Evaluates `expr`: returns the first value from the `values` list whose corresponding match
> from the `matches` list is equal to `expr`; returns `value_if_no_match` if `expr` is not
> equal to any of the matches in the `matches` list
>
> > [!NOTE]
> >
> > A *null* cannot be used for either a match or value, but `value_if_no_match` can be
> > null.
>
> <table>
>   <thead>
>     <tr>
>       <th>Parameter</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`expr`</td>
>       <td>any expression to match against the list of `matches`</td>
>     </tr>
>
>     <tr>
>       <td>`matches`</td>
>       <td>a comma-delimited list of constants to match `expr` against; needs to be of the same data type as `expr` and have the same number of list items as the `values` list</td>
>     </tr>
>
>     <tr>
>       <td>`values`</td>
>       <td>a comma-delimited list of constants, one of which will be returned in the event that `expr` matches an item in the `matches` list; needs to be of the same data type as `value_if_no_match` and have the same number of list items as the `matches` list</td>
>     </tr>
>
>     <tr>
>       <td>`value_if_no match`</td>
>       <td>any value to return in the event of a match; needs to be of the same data type as the list items in `values`</td>
>     </tr>
>   </tbody>
> </table>
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`CASE(0, {1, 2, 3}, {'A', 'B', 'C'}, 'D')`</td>
>       <td>`D`</td>
>     </tr>
>
>     <tr>
>       <td>`CASE(1, {1, 2, 3}, {'A', 'B', 'C'}, 'D')`</td>
>       <td>`A`</td>
>     </tr>
>
>     <tr>
>       <td>`CASE(2, {1, 2, 3}, {'A', 'B', 'C'}, 'D')`</td>
>       <td>`B`</td>
>     </tr>
>
>     <tr>
>       <td>`CASE(3, {1, 2, 3}, {'A', 'B', 'C'}, 'D')`</td>
>       <td>`C`</td>
>     </tr>
>
>     <tr>
>       <td>`CASE(4, {1, 2, 3}, {'A', 'B', 'C'}, 'D')`</td>
>       <td>`D`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] IF(expr, value\_if\_true, value\_if\_false)
>
> Evaluates `expr`: if *true*, returns `value_if_true`; otherwise, if *false* or *null*,
> returns `value_if_false`; see [Short-Circuiting](https://docs.kinetica.com/content/concepts/expressions.md#short-circuiting) for error-checking details
>
> <table>
>   <thead>
>     <tr>
>       <th>Parameter</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`expr`</td>
>       <td>any *true*/*false* condition \[!NOTE] When an integer column is used directly, this function will interpret non-zero values as *true* and zero values as *false*.</td>
>     </tr>
>
>     <tr>
>       <td>`value_if_true`</td>
>       <td>any type; must be the same type as `value_if_false`</td>
>     </tr>
>
>     <tr>
>       <td>`value_if_false`</td>
>       <td>any type; must be the same type as `value_if_true`</td>
>     </tr>
>   </tbody>
> </table>

### Conversion Functions

For the `CAST()` and `CONVERT()` functions, valid destination types are:

| Numeric | Text | Date/Time | Geometry |
| - | - | - | - |
| \* *bool*  \* *int8*  \* *int16*  \* *int*  \* *long*  \* *ulong*  \* *float*  \* *double*  \* *decimal* | \* *string*  \* *char1*  \* *char2*  \* *char4*  \* *char8*  \* *char16*  \* *char32*  \* *char64*  \* *char128*  \* *char256* | \* *timestamp*  \* *date*  \* *time*  \* *datetime* | \* *geometry* |

> [accordion] CAST (original value, destination type)
>
> Returns the equivalent of `original value` converted to the  `destination type`;
> useful for converting strings to numbers and numbers to strings

> [accordion] CHAR(expr)
>
> Returns the character associated with the ASCII code in `expr`

> [accordion] CHAR1(expr)
>
> Converts the given `expr` to *char1* type

> [accordion] CHAR2(expr)
>
> Converts the given `expr` to *char2* type

> [accordion] CHAR4(expr)
>
> Converts the given `expr` to *char4* type

> [accordion] CHAR8(expr)
>
> Converts the given `expr` to *char8* type

> [accordion] CHAR16(expr)
>
> Converts the given `expr` to *char16* type

> [accordion] CHAR32(expr)
>
> Converts the given `expr` to *char32* type

> [accordion] CHAR64(expr)
>
> Converts the given `expr` to *char64* type

> [accordion] CHAR128(expr)
>
> Converts the given `expr` to *char128* type

> [accordion] CHAR256(expr)
>
> Converts the given `expr` to *char256* type

> [accordion] CONVERT (original value, destination type, style)
>
> Returns the equivalent of `original value` converted to the `destination type`. The
> `style` parameter is currently only applicable when the `destination type` is
> *string* and the `original value` is of *timestamp* or *datetime* type.
>
> Valid style codes include:
>
> <table>
>   <thead>
>     <tr>
>       <th>Style</th>
>       <th>Format</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`0`</td>
>       <td>`mon dd yyyy hh:mi<AM|PM>`</td>
>     </tr>
>
>     <tr>
>       <td>`21` `121`</td>
>       <td>`yyyy-mm-dd hh:mi:ss.mmm`</td>
>     </tr>
>   </tbody>
> </table>
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`CONVERT('0.1', double)`</td>
>       <td>`0.1`</td>
>     </tr>
>
>     <tr>
>       <td>`CONVERT(DATETIME('2000-10-10 12:34:56'), string, 0)`</td>
>       <td>`Oct 10 2000 12:34PM`</td>
>     </tr>
>
>     <tr>
>       <td>`CONVERT(DATETIME(971181296789), string, 21)`</td>
>       <td>`2000-10-10 12:34:56.789`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] DATE(expr)
>
> Converts `expr` to date (`YYYY-MM-DD`) format

> [accordion] DATETIME(expr)
>
> Converts `expr` to datetime (`YYYY-MM-DD HH24:MI:SS.mmm`) format

> [accordion] DECIMAL(expr)
>
> Converts the given `expr` to *decimal* type

> [accordion] DOUBLE(expr)
>
> Converts the given `expr` to *double* type

> [accordion] FLOAT(expr)
>
> Converts the given `expr` to *float* type

> [accordion] INT(expr)
>
> Converts the given `expr` to *int* type

> [accordion] LONG(expr)
>
> Converts the given `expr` to *long* type

> [accordion] STRING(expr)
>
> Converts `expr` to a string format appropriate for the `expr` type

> [accordion] TIME(expr)
>
> Converts `expr` to time (`HH:MI:SS.mmm`) format

> [accordion] TIMESTAMP(expr)
>
> Converts `expr` to the number of milliseconds since the epoch

> [accordion] TO\_CHAR(expr, format)
>
> Converts the given date/time `expr` to a string matching the given `format`.
> The returned string will be truncated at 32 characters.
> See [Date/Time Conversion Codes](https://docs.kinetica.com/content/concepts/expressions.md#datetime-conversion-codes) for the list of format codes.
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`TO_CHAR(DATETIME(971181296000), '"Last login: "YYYY-MM-DD')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`Last login: 2000-10-10`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] TO\_DATE(string, format)
>
> Converts the given string to a *date* type with the given format code.
> See [Date/Time Conversion Codes](https://docs.kinetica.com/content/concepts/expressions.md#datetime-conversion-codes) for the list of format codes.
>
> Example:
>
> ```
> TO_DATE('2017-06-15', 'YYYY-MM-DD')
> ```

> [accordion] TO\_DATETIME(string, format)
>
> Converts the given string to a *datetime* type with the given format code.
> See [Date/Time Conversion Codes](https://docs.kinetica.com/content/concepts/expressions.md#datetime-conversion-codes) for the list of format codes.
>
> Example:
>
> ```
> TO_DATETIME('2017-06-15 10:37:30', 'YYYY-MM-DD HH:MI:SS')
> ```

> [accordion] TO\_TIME(string, format)
>
> Converts the given string to a *time* type with the given format code.
> See [Date/Time Conversion Codes](https://docs.kinetica.com/content/concepts/expressions.md#datetime-conversion-codes) for the list of format codes.
>
> Example:
>
> ```
> TO_TIME('10:37:30', 'HH:MI:SS')
> ```

> [accordion] TO\_TIMESTAMP(string, format)
>
> Converts the given string to a *timestamp* type with the given format code.
> See [Date/Time Conversion Codes](https://docs.kinetica.com/content/concepts/expressions.md#datetime-conversion-codes) for the list of format codes.
>
> Example:
>
> ```
> TO_TIMESTAMP('2017-06-15 10:37:30', 'YYYY-MM-DD HH:MI:SS')
> ```

> [accordion] ULONG(expr)
>
> Converts the given `expr` to *ulong* type

> [accordion] VECTOR(expr, len)
>
> Converts the given stringified array of `len` number of *float* values in `expr` to
> `VECTOR` type.
>
> Example:
>
> ```
> VECTOR('[1.1, 2.2, 3.3]', 3)
> ```

#### Date/Time Conversion Codes

The following formatting codes can be used to convert date/time strings to
native date/time objects (with `TO_DATE`, `TO_DATETIME`, `TO_TIME` and `TO_TIMESTAMP`)
and for formatting date/time objects as strings (with `TO_CHAR`).

These characters are interpreted literally:  `-` `/` `,` `.` `;` `:`

Other characters need to be quoted in order to be interpreted literally.
For example, `MM-DD-YYYY` can be used to convert `01-02-2022` to a date,
while `"Today is "MM-DD-YYYY` is needed to convert `Today is 01-02-2022`.

In the following table, `Opt` in the Input column indicates that the field may be empty
when being read, and still be considered a valid input.  This can be useful when reading
data from a source that, for example, sometimes includes milliseconds in their time strings
and sometimes does not (e.g., the `MMM` code is `Opt`).  `Yes` in the Input column indicates
that some data must be present in the input string to be considered valid, unless it is after
a `$` character, in which case all input after the `$` is optional.

| Format Code | Input | Output | Description |
| - | - | - | - |
| `_` | Yes | | Any one character |
| `?` | Opt | | Zero or more non-digit characters |
| `$` | Yes | | Everything after this is optional; e.g., `HH:MI$:SS` would accept `12:34` and `12:34:56` |
| `AD` | | Yes | Era indicator without periods |
| `A.D.` | | Yes | Era indicator with periods |
| `AM` | Yes | Yes | Meridian indicator without periods \[`AM`, `PM`] |
| `A.M.` | Yes | Yes | Meridian indicator with periods \[`A.M.`, `P.M.`] |
| `BC` | | Yes | Era indicator without periods |
| `B.C.` | | Yes | Era indicator with periods |
| `C` | Yes | Yes | Number of day in calendar month, with optional leading zero \[`1` - `31`] |
| `CC` | | Yes | Century (if last 2 digits of the 4-digit year are `00`, this is the first 2 digits; otherwise, this is first 2 digits + 1) |
| `D` | Yes | Yes | Day of week \[`1` - `7`] (*Sunday* - *Saturday*) |
| `DAY` | Yes | Yes | Day of week \[`Sunday` - `Saturday`] |
| `DD` | Yes | Yes | Number of day in month, with leading zero \[`01` - `31`] |
| `DDD` | Yes | Yes | Number of day of year \[`1` - `366`] |
| `DL` | Yes | Yes | Date long format (`DAY, MONTH C, RRRR`) |
| `DS` | Yes | Yes | Date short format (`M/C/RRRR`) |
| `DY` | Yes | Yes | Abbreviated day name (e.g., "Mon") |
| `FF[1-9]` | Opt | Yes | Fractional seconds where the number of fractional second digits can be specified (default is 3 digits); when used for input, the string may contain an optional "." preceding the numbers |
| `H` | Yes | Yes | Alias for `H12` |
| `H12` | Yes | Yes | Hour of day in 12-hour format, with optional leading zero \[`0` - `11`] |
| `H24` | Yes | Yes | Hour of day in 24-hour format, with optional leading zero \[`0` - `23`] |
| `HH` | Yes | Yes | Alias for `HH12` |
| `HH12` | Yes | Yes | Hour of day in 12-hour format, with leading zero \[`00` - `11`] |
| `HH24` | Yes | Yes | Hour of day in 24-hour format, with leading zero \[`00` - `23`] |
| `I` | Yes | Yes | Last digit of ISO year |
| `ID` | Yes | Yes | ISO 8601 day of week \[`1` - `7`] (*Monday* - *Sunday*) |
| `IDDD` | Yes | Yes | ISO 8601 day of year \[`001` - `371`] (where `001` is the *Monday* of the 1st ISO week) |
| `IW` | Yes | Yes | ISO 8601 week of year \[`01` - `53`] (where `01` contains the first *Thursday* of the year) |
| `IY` | Yes | Yes | Last 2 digits of ISO year |
| `IYY` | Yes | Yes | Last 3 digits of ISO year |
| `IYYY` | Yes | Yes | Last 4 digits of ISO year |
| `J` | Yes | Yes | Julian day; the number of days since *January 1, 4712 BC*.  Number specified with `J` must be integers. |
| `LLL` | Opt | Yes | Whole milliseconds (often positioned after a colon); e.g., `12:34:56:78` => *78 milliseconds*; when used for input, the string may contain an optional "." or ":" preceding the numbers; when "." is found, this code will act like the `MMM` code |
| `M` | Yes | Yes | Number of month in year, with optional leading zero \[`1` - `12`] |
| `MI` | Yes | Yes | Minute of hour \[`00` - `59`] |
| `MM` | Yes | Yes | Number of month in year, with leading zero \[`01` - `12`] |
| `MMM` | Opt | Yes | Fractions of a second up to milliseconds; e.g., `12:34:56.78` => *780 milliseconds*; when used for input, the string may contain an optional "." or ":" preceding the numbers; when ":" is found, this code will act like the `LLL` code |
| `MON` | Yes | Yes | 3-character abbreviation of month in title case \[`Jan` - `Dec`] |
| `MONTH` | Yes | Yes | Full name of month \[`January` - `December`] |
| `MS` | Opt | Yes | Alias for `MMM` |
| `OF` | Opt | Yes | Time-zone offset from UTC (`TZHTZM`) |
| `PM` | Yes | Yes | Alias for `AM` |
| `P.M.` | Yes | Yes | Alias for `A.M.` |
| `Q` | | Yes | Quarter of the year \[`1` - `4`] (*January-March* - *October-December*) |
| `RM` | Yes | Yes | Roman numeral month \[`I` - `XII`] (*January* - *December*) |
| `RR` | Yes | Yes | Rounded year.  Assume the given 2-digit year occurs in the present century, then:   \* If the assumed date is greater than 50 years into the future, declare the date to be in the previous century  \* If the assumed date is greater than 50 years into the past, declare the date to be in the next century |
| `RRRR` | Yes | Yes | Either a 2-digit or 4-digit year; if 2-digit, equivalent to `RR` |
| `SCC` | | Yes | Same as `CC` |
| `SS` | Yes | Yes | Second of minute \[`00` - `59`] |
| `SSSS` | Yes | Yes | Alias for `SSSSS` |
| `SSSSS` | Yes | Yes | Seconds past midnight \[`0` - `86399`] |
| `SYEAR` | | Yes | Same as `YEAR` |
| `SYYYY` | Yes | Yes | Same as `YYYY` |
| `TS` | Yes | Yes | Time short format (`H24:MI:SS.MMM`) |
| `TZ` | Opt | Yes | Time zone (`TZH`) |
| `TZH` | Opt | Yes | Time zone hour (ISO); "Z" or +/- followed by one or two digits (will always output "Z") |
| `TZM` | Opt | Yes | Time zone minute (ISO); colon followed by one or two digits; for input, an optional colon is allowed at the front; if present, two digits must follow it |
| `US` | Opt | Yes | Microseconds; when used for input, the string may contain an optional "." preceding the numbers |
| `W` | Yes | Yes | Week of month \[`1` - `5`], where week 1 starts on the first day of the month and ends on the seventh |
| `WW` | Yes | Yes | Week of year \[`1` - `53`], where week 1 starts on the first day of the year and continues to the seventh day of the year |
| `X` | Yes | Yes | Local radix character (always `.`.  E.g., `HH:MI:SSXFF`) |
| `Y` | Yes | Yes | Last 1 digit of year |
| `Y,YYY` | Yes | Yes | Year with a comma after the thousands place |
| `YEAR` | | Yes | Year spelled out (e.g., "Two Thousand Twenty Five") |
| `YY` | Yes | Yes | Last 2 digits of year |
| `YYY` | Yes | Yes | Last 3 digits of year |
| `YYYY` | Yes | Yes | 4-digit year |

### Date/Time Functions

This section comprises the following functions:

* [Date/Time Base Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-datetime-base), which can extract parts of
  date/time expressions, convert back and forth between data types, and return
  the current date/time
* [Date/Time Complex Conversion Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-datetime-complex), which can perform more complex
  date/type conversions

The date/time units these functions accept, and the spellings each one allows,
are listed under [Date/Time Units](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-datetime-units).

#### Date/Time Units

Functions that take a date/time `unit` (or `part`) accept any of the following
codes, which are case-insensitive.  The unit may be given unquoted or as a string
literal.

| Unit | Accepted Codes |
| - | - |
| Year | `YEAR`, `YEARS`, `YY`, `YYYY`, `SQL_TSI_YEAR` |
| Quarter | `QUARTER`, `QUARTERS`, `QQ`, `Q`, `SQL_TSI_QUARTER` |
| Month | `MONTH`, `MONTHS`, `MM`, `M`, `SQL_TSI_MONTH` |
| Week | `WEEK`, `WEEKS`, `WK`, `WW`, `SQL_TSI_WEEK` |
| Day | `DAY`, `DAYS`, `DD`, `D`, `SQL_TSI_DAY` |
| Hour | `HOUR`, `HOURS`, `HH`, `SQL_TSI_HOUR` |
| Minute | `MINUTE`, `MINUTES`, `MI`, `N`, `SQL_TSI_MINUTE` |
| Second | `SECOND`, `SECONDS`, `SS`, `S`, `SQL_TSI_SECOND` |
| Millisecond | `MILLISECOND`, `MILLISECONDS`, `MS`, `SQL_TSI_MILLISECOND` |
| Weekday | `WEEKDAY`, `DAYOFWEEK`, `DW`, `W` |
| Day of Year | `DAYOFYEAR`, `DY`, `Y` |

The unit is optional in every function that takes one as its first argument,
and defaults to `DAY`.  The one exception is `ST_TRACKDURATION`, which
reports a duration rather than a date and so defaults to `MILLISECOND`.

> [!NOTE]
>
> `WEEKDAY` and `DAYOFYEAR` (and their aliases) name a component of a date
> rather than a length of time, so there is no interval to add or truncate to.
> They are therefore only applicable to the functions that extract a component,
> such as `DATEPART`.

#### Date/Time Base Functions

> [accordion] CLOCK\_TIMESTAMP()
>
> Returns the date & time as `YYYY-MM-DD HH24:MI:SS.mmm`
>
> > [!NOTE]
> >
> > `CLOCK_TIMESTAMP` may return different values each time it is called in the
> > same query or SQL Procedure, which may lead to data getting out of sync across HA
> > clusters.  Use `CURRENT_DATETIME` to avoid this issue.

> [accordion] CURRENT\_DATE()
>
> Returns the date as `YYYY-MM-DD`

> [accordion] CURRENT\_DATETIME()
>
> Returns the date & time as `YYYY-MM-DD HH24:MI:SS.mmm`
>
> > [!NOTE]
> >
> > `CURRENT_DATETIME` will return same values each time it is called in the
> > same query or SQL Procedure, and should keep data in-sync across HA clusters.
> > See `CLOCK_TIMESTAMP` to always get the actual time each time it is called.

> [accordion] CURRENT\_TIME()
>
> Returns the time as `HH24:MI:SS.mmm`

> [accordion] CURRENT\_TIMESTAMP()
>
> Returns the date & time as the number of milliseconds since the epoch

> [accordion] DATEADD (\[unit,] amount, expr)
>
> Adds the positive or negative integral `amount` of `unit` date/time intervals to the
> `date`, `datetime`, or `time` value in `expr`
>
> The default `unit` is `DAY`.
>
> The following date/time intervals are supported for `unit`, each of which
> also has the alternate codes listed in [Date/Time Units](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-datetime-units):
>
> <table>
>   <thead>
>     <tr>
>       <th>Constant</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`YEAR`</td>
>       <td>Year is modified by interval amount (not affected by leap year, etc.) overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`QUARTER`</td>
>       <td>Month is modified by three times the interval amount, irrespective of the number of days in the months between; day adjusting performed the same as the `MONTH` description, but only on final month (e.g., *Jan 31st* + *1 quarter* will be *Apr 30th*, not *Apr 28th* because of *February*)</td>
>     </tr>
>
>     <tr>
>       <td>`MONTH`</td>
>       <td>Month is modified by interval amount and date adjusted if overflow/underflow occurs; day adjusted to last day of calculated month if not a valid day for that month (e.g., *Apr 31st* -> *Apr 30th*)</td>
>     </tr>
>
>     <tr>
>       <td>`WEEK`</td>
>       <td>Day is modified by 7 times the interval amount (time not affected by daylight savings time, etc.); month & year are adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`DAY`</td>
>       <td>Day is modified by interval amount (time not affected by daylight savings time, etc.); date is adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`HOUR`</td>
>       <td>Hours are modified by interval amount (time not affected by daylight savings time, etc.); date is adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`MINUTE`</td>
>       <td>Minutes are modified by interval amount; date/time are adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`SECOND`</td>
>       <td>Seconds are modified by interval amount; date/time are adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`MILLISECOND`</td>
>       <td>Milliseconds are modified by interval amount; date/time are adjusted, if overflow/underflow occurs</td>
>     </tr>
>   </tbody>
> </table>
>
> > [!NOTE]
> >
> > Any of these `unit` types can have a `SQL_TSI_` prefix prepended to them;
> > e.g., both `DAY` and `SQL_TSI_DAY` are valid `unit` types for specifying a day
> > interval.  They may also be single-quoted or unquoted.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result *(in string format)*</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`DATEADD(YEAR, 1, '2000-10-10')`</td>
>       <td>`2001-10-10`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(QUARTER, 1, '2000-11-30')`</td>
>       <td>`2001-02-28`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(MONTH, 1, '2000-01-31')`</td>
>       <td>`2000-02-29`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(WEEK, 53, '2000-01-01')`</td>
>       <td>`2001-01-06`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(DAY, 1, '2000-12-31')`</td>
>       <td>`2001-01-01`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(HOUR, 12, '2000-10-10 12:34:56')`</td>
>       <td>`2000-10-11 00:34:56.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(MINUTE, 1, '2000-10-10 12:34:56')`</td>
>       <td>`2000-10-10 12:35:56.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(SECOND, 1, '2000-12-31 23:59:59')`</td>
>       <td>`2001-01-01 00:00:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(MILLISECOND, 1, '2000-10-10 12:34:56')`</td>
>       <td>`2000-10-10 12:34:56.001`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEADD(SECOND, 1, TIME('12:34:56'))`</td>
>       <td>`12:34:57.000`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] DATE\_BUCKET (width, ds\[, offset\[, base]])
>
> Calculates the date range in which a given date `ds` falls, based on a set of
> fixed-width "buckets" with the given `width`, start-aligned `base` date, and
> `offset` from that `base` date
>
> The `width` is the number of days each bucket should span.
>
> The `offset` is the number of days after (positive `offset`) or number of days before
> (negative `offset`) the `base` date to which the buckets should be aligned.  The
> default is no offset.
>
> The default `base` is `2000-01-03`.
>
> For example, given the following call:
>
> ```
> DATE_BUCKET(7, ds, -3, '2023-02-21')
> ```
>
> The call will be processed as follows:
>
> * The given date `ds` will be slotted into a date bucket
> * The bucket will span a range of `7` days
> * The baseline bucket will start at `2023-02-18` (`2023-02-21` offset by `-3` days)
>   and continue through `2023-02-24` (`7` days, including `2023-02-18`)
> * Buckets will extend before & after the baseline bucket in contiguous, non-overlapping
>   fashion
> * The result record will show the date at the beginning of the bucket's date range

> [accordion] DATEDIFF (\[unit,] begin, end)
>
> Calculates the difference between two date/time expressions, returning the result as an
> integral difference in the units specified; more precisely, how many whole date/time
> intervals of type `unit` need to be added to (or subtracted from) `begin` to equal
> `end` (or get as close as possible **without** going past it) using the unit types and
> the rules specified in `TIMESTAMPADD`.
>
> The default `unit` is `DAY`.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`DATEDIFF('2000-10-10', '2000-12-31')`</td>
>       <td>`82`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEDIFF('2000-03-31', '2000-04-30')`</td>
>       <td>`30`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEDIFF('2000-12-31', '2000-10-10')`</td>
>       <td>`-82`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEDIFF('2000-10-10 12:34:56.789', 978222896678)`</td>
>       <td>`81`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEDIFF(MONTH, '2000-10-10', '2000-12-31')`</td>
>       <td>`2`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEDIFF(MONTH, '2000-03-31', '2000-04-30')`</td>
>       <td>`0`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEDIFF(MONTH, '2000-12-31', '2000-10-10')`</td>
>       <td>`-2`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEDIFF(HOUR, '2000-10-10 12:34:56.789', 978222896678)`</td>
>       <td>`1955`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] DATEPART(\[part,] expr)
>
> Returns the requested `part` of the date/time `expr`.
>
> The default `part` is `DAY`.
>
> The `part` may be any of those specified in `DATE_TRUNC(part, expr)`, plus
> the following, each of which also has the alternate codes listed in
> [Date/Time Units](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-datetime-units):
>
> <table>
>   <thead>
>     <tr>
>       <th>Constant</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`WEEKDAY`</td>
>       <td>Return the day of the week \[`1` - `7`].</td>
>     </tr>
>
>     <tr>
>       <td>`DAYOFYEAR`</td>
>       <td>Return the day of the year \[`1` - `366`].</td>
>     </tr>
>
>     <tr>
>       <td>`SECS_SINCE_EPOCH`</td>
>       <td>Return the number of seconds since the epoch (1970-01-01).</td>
>     </tr>
>
>     <tr>
>       <td>`MSECS_SINCE_EPOCH`</td>
>       <td>Return the number of milliseconds since the epoch.</td>
>     </tr>
>   </tbody>
> </table>
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`DATEPART(YEAR, '2000-12-31')`</td>
>       <td>`2000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEPART(MONTH, '2000-03-31 12:34:56.000')`</td>
>       <td>`3`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEPART(DAY, '2000-03-31 12:34:56.000')`</td>
>       <td>`31`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEPART(SECOND, '2000-03-31 12:34:56.220')`</td>
>       <td>`56`</td>
>     </tr>
>
>     <tr>
>       <td>`DATEPART(MSECS_SINCE_EPOCH, '2000-03-31 12:34:56.220')`</td>
>       <td>`954506096220`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] DATE\_TRUNC(\[part,] expr)
>
> Returns the date/time `expr` after truncating it beyond the given date/time `part`.
>
> The default `part` is `DAY`.
>
> The following date/time constants are supported for `part`, each of which
> also has the alternate codes listed in [Date/Time Units](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-datetime-units):
>
> <table>
>   <thead>
>     <tr>
>       <th>Constant</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`YEAR`</td>
>       <td>Return the first day of the year in which `expr` occurs</td>
>     </tr>
>
>     <tr>
>       <td>`QUARTER`</td>
>       <td>Return the first day of the quarter in which `expr` occurs</td>
>     </tr>
>
>     <tr>
>       <td>`MONTH`</td>
>       <td>Return the first day of the month in which `expr` occurs</td>
>     </tr>
>
>     <tr>
>       <td>`WEEK`</td>
>       <td>Return the first day of the week in which `expr` occurs</td>
>     </tr>
>
>     <tr>
>       <td>`DAY`</td>
>       <td>Return the date (at midnight) on which `expr` occurs</td>
>     </tr>
>
>     <tr>
>       <td>`HOUR`</td>
>       <td>Return the timestamp up to the hour in which `expr` occurs</td>
>     </tr>
>
>     <tr>
>       <td>`MINUTE`</td>
>       <td>Return the timestamp up to the minute in which `expr` occurs</td>
>     </tr>
>
>     <tr>
>       <td>`SECOND`</td>
>       <td>Return the timestamp up to the second in which `expr` occurs</td>
>     </tr>
>
>     <tr>
>       <td>`MILLISECOND`</td>
>       <td>Return the timestamp up to the millisecond in which `expr` occurs</td>
>     </tr>
>   </tbody>
> </table>
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`DATE_TRUNC(YEAR, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-01-01 00:00:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATE_TRUNC(QUARTER, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-07-01 00:00:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATE_TRUNC(MONTH, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-09-01 00:00:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATE_TRUNC(WEEK, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-09-07 00:00:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATE_TRUNC(DAY, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-09-10 00:00:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATE_TRUNC(HOUR, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-09-10 12:00:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATE_TRUNC(MINUTE, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-09-10 12:34:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATE_TRUNC(SECOND, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-09-10 12:34:56.000`</td>
>     </tr>
>
>     <tr>
>       <td>`DATE_TRUNC(MILLISECOND, '2008-09-10 12:34:56.789')`</td>
>       <td>`2008-09-10 12:34:56.789`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] DAY(expr)
>
> Alias for `DAYOFMONTH(expr)`

> [accordion] DAYNAME(expr)
>
> Extracts the day of the week from `expr` and converts it to the corresponding day name
> \[`Sunday` - `Saturday` ]

> [accordion] DAYOFMONTH(expr)
>
> Extracts the day of the month from `expr` \[`1` - `31`]

> [accordion] DAYOFWEEK(expr)
>
> Extracts the day of the week from `expr` \[`1` - `7`]
>
> <table>
>   <thead>
>     <tr>
>       <th>Expression Value</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>Date on *Sunday*</td>
>       <td>`1`</td>
>     </tr>
>
>     <tr>
>       <td>Date on *Monday*</td>
>       <td>`2`</td>
>     </tr>
>
>     <tr>
>       <td>Date on *Tuesday*</td>
>       <td>`3`</td>
>     </tr>
>
>     <tr>
>       <td>Date on *Wednesday*</td>
>       <td>`4`</td>
>     </tr>
>
>     <tr>
>       <td>Date on *Thursday*</td>
>       <td>`5`</td>
>     </tr>
>
>     <tr>
>       <td>Date on *Friday*</td>
>       <td>`6`</td>
>     </tr>
>
>     <tr>
>       <td>Date on *Saturday*</td>
>       <td>`7`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] DAY\_OF\_WEEK(expr)
>
> Alias for `DAYOFWEEK(expr)`

> [accordion] DAYOFYEAR(expr)
>
> Extracts the day of the year from `expr` \[`1` - `366`]

> [accordion] DAY\_OF\_YEAR(expr)
>
> Alias for `DAYOFYEAR(expr)`

> [accordion] EPOCH\_MSECS\_TO\_DATETIME(expr)
>
> Converts `expr` milliseconds since the epoch to a date/time
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`EPOCH_MSECS_TO_DATETIME(971181296789)`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`2000-10-10 12:34:56.789`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] EPOCH\_SECS\_TO\_DATETIME(expr)
>
> Converts `expr` seconds since the epoch to a date/time
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`EPOCH_SECS_TO_DATETIME(971181296)`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`2000-10-10 12:34:56.000`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] HOUR(expr)
>
> Extracts the hour of the day from `expr` \[`0` - `23`]

> [accordion] LAST\_DAY(expr)
>
> Returns the date of the last day of the month in the given `expr`

> [accordion] MINUTE(expr)
>
> Extracts the minute of the day from `expr` \[`0` - `59`]

> [accordion] MONTH(expr)
>
> Extracts the month of the year from `expr` \[`1` - `12`]

> [accordion] MONTHNAME(expr)
>
> Extracts the month of the year from `expr` and converts it to the corresponding month
> name \[ `January` - `December`]

> [accordion] MSEC(expr)
>
> Extracts the millisecond of the second from `expr` \[`0` - `999`]

> [accordion] MSECS\_SINCE\_EPOCH(expr)
>
> Converts `expr` date/time to the number of milliseconds since the epoch
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`MSECS_SINCE_EPOCH('2000-10-10 12:34:56.789')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`971181296789`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] NEXT\_DAY(date, expr)
>
> Returns the date of the next day of the week, provided as a day name in `expr`, that
> occurs after the given `date`
>
> Some examples, given that *2000-10-10* is a *Tuesday*:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`NEXT_DAY('2000-10-10', 'Wednesday')`</td>
>       <td>`2000-10-11`</td>
>     </tr>
>
>     <tr>
>       <td>`NEXT_DAY('2000-10-10', 'Friday')`</td>
>       <td>`2000-10-13`</td>
>     </tr>
>
>     <tr>
>       <td>`NEXT_DAY('2000-10-10', 'Tuesday')`</td>
>       <td>`2000-10-17`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] NOW()
>
> Alias for `CURRENT_DATETIME()`

> [accordion] QUARTER(expr)
>
> Extracts the quarter of the year from `expr` \[`1` - `4`]
>
> <table>
>   <thead>
>     <tr>
>       <th>Expression Value</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>Date in *January*, *February*, or *March*</td>
>       <td>`1`</td>
>     </tr>
>
>     <tr>
>       <td>Date in *April*, *May*, or *June*</td>
>       <td>`2`</td>
>     </tr>
>
>     <tr>
>       <td>Date in *July*, *August*, or *September*</td>
>       <td>`3`</td>
>     </tr>
>
>     <tr>
>       <td>Date in *October*, *November*, or *December*</td>
>       <td>`4`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] SEC(expr)
>
> Alias for `SECOND(expr)`

> [accordion] SECOND(expr)
>
> Extracts the seconds of the minute from `expr` \[ `0` - `59` ]

> [accordion] SECS\_SINCE\_EPOCH(expr)
>
> Converts `expr` date/time to the number of seconds since the epoch
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`SECS_SINCE_EPOCH('2000-10-10 12:34:56')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`971181296`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] SLEEP(expr)
>
> Pause execution for at least `expr` seconds, though system load may delay the return
> from this call for longer than the specified amount.  Use a decimal for `expr` to pause
> for less than a second; e.g., `SLEEP(0.001)` will pause for at least 1 millisecond.
> `SLEEP` should be invoked without a table reference in the call to avoid being called
> for every record in a result set; e.g., in Python:
>
> ```
> db.get_records_by_column('', 'SLEEP(0.001)')
> ```

> [accordion] TIMEBOUNDARYDIFF (\[unit,] begin, end)
>
> Calculates the difference between two date/time expressions, returning the result as an
> integral difference in the units specified; more precisely, how many whole date/time
> intervals of type `unit` need to be added to (or subtracted from) `begin` to equal
> `end` *up to the precision of the* `unit` *specified*, using the unit types and rules
> specified in `TIMESTAMPADD`.
>
> The default `unit` is `DAY`.
>
> For example, if `unit` were `MONTH`, only the year & month of `begin` and `end`
> would be used in the calculation; if `unit` were `DAY`, any time portion from
> `begin` & `end` would be dropped, and so on.  This is unlike `TIMESTAMPDIFF`, which
> will consider the entirety of both `begin` & `end` in the calculation.
>
> > [!NOTE]
> >
> > This *is* symmetric with `TIMESTAMPADD` in all cases, as adding *1* `MONTH`
> > to *Mar 31st* results in *Apr 30th*, and the `TIMEBOUNDARYDIFF` in `MONTH` units
> > between those two dates is *1*.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`TIMEBOUNDARYDIFF(MONTH, DATE('2000-10-10'), DATE('2000-12-31'))`</td>
>       <td>`2`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMEBOUNDARYDIFF(MONTH, DATE('2000-03-31'), DATE('2000-04-30'))`</td>
>       <td>`1`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMEBOUNDARYDIFF(MONTH, DATE('2000-12-31'), DATE('2000-10-10'))`</td>
>       <td>`-2`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMEBOUNDARYDIFF(HOUR, 978222896000, DATETIME('2000-10-10 12:34:56'))`</td>
>       <td>`-1956`</td>
>     </tr>
>   </tbody>
> </table>
>
> > [!NOTE]
> >
> > This function does not accept time-only string literals (e.g.,
> > `'12:34:56'`); cast them first, e.g. `TIME('12:34:56')`.  Date & datetime string
> > literals (e.g., `'2000-12-31'`, `'2000-12-31 12:34:56'`) are accepted directly, as
> > are `DATE`, `TIME`, `DATETIME` & `TIMESTAMP` values and epoch milliseconds.

> [accordion] TIME\_BUCKET (width, ts\[, offset\[, base]])
>
> Calculates the date/time range in which a given timestamp `ts` falls, based on a set of
> fixed-width "buckets" with the given `width`, start-aligned `base` date/time, and
> `offset` from that `base` date/time
>
> The `width` is the number of milliseconds each bucket should span.
>
> The `offset` is the number of milliseconds after (positive `offset`) or number of
> milliseconds before (negative `offset`) the `base` date/time to which the buckets
> should be aligned.  The default is no offset.
>
> The default `base` is `2000-01-03 00:00:00`.
>
> For example, given the following call:
>
> ```
> TIME_BUCKET(5 * 60 * 1000, ts, -2.5 * 60 * 1000, '2023-02-28')
> ```
>
> The call will be processed as follows:
>
> * The given timestamp `ts` will be slotted into a date/time bucket
> * The bucket will span a range of `5` minutes
> * The baseline bucket will start at `2023-02-27 23:57:30` (`2023-02-28` offset by
>   `-2.5` minutes) and continue through `2023-02-28 00:02:30` (`5` minutes from
>   `2023-02-27 23:57:30`)
> * Buckets will extend before & after the baseline bucket in contiguous, non-overlapping
>   fashion
> * The result record will show the timestamp at the beginning of the bucket's range

> [accordion] TIMESTAMPADD (\[unit,] amount, expr)
>
> Adds the positive or negative integral `amount` of `unit` date/time intervals to the
> `date`, `datetime`, or `time` value in `expr`
>
> The default `unit` is `DAY`.
>
> The following date/time intervals are supported for `unit`, each of which
> also has the alternate codes listed in [Date/Time Units](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-datetime-units):
>
> <table>
>   <thead>
>     <tr>
>       <th>Constant</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`YEAR`</td>
>       <td>Year is modified by interval amount (not affected by leap year, etc.) overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`QUARTER`</td>
>       <td>Month is modified by three times the interval amount, irrespective of the number of days in the months between; day adjusting performed the same as the `MONTH` description, but only on final month (e.g., *Jan 31st* + *1 quarter* will be *Apr 30th*, not *Apr 28th* because of *February*)</td>
>     </tr>
>
>     <tr>
>       <td>`MONTH`</td>
>       <td>Month is modified by interval amount and date adjusted if overflow/underflow occurs; day adjusted to last day of calculated month if not a valid day for that month (e.g., *Apr 31st* -> *Apr 30th*)</td>
>     </tr>
>
>     <tr>
>       <td>`WEEK`</td>
>       <td>Day is modified by 7 times the interval amount (time not affected by daylight savings time, etc.); month & year are adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`DAY`</td>
>       <td>Day is modified by interval amount (time not affected by daylight savings time, etc.); date is adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`HOUR`</td>
>       <td>Hours are modified by interval amount (time not affected by daylight savings time, etc.); date is adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`MINUTE`</td>
>       <td>Minutes are modified by interval amount; date/time are adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`SECOND`</td>
>       <td>Seconds are modified by interval amount; date/time are adjusted, if overflow/underflow occurs</td>
>     </tr>
>
>     <tr>
>       <td>`MILLISECOND`</td>
>       <td>Milliseconds are modified by interval amount; date/time are adjusted, if overflow/underflow occurs</td>
>     </tr>
>   </tbody>
> </table>
>
> > [!NOTE]
> >
> > Any of these `unit` types can have a `SQL_TSI_` prefix prepended to them;
> > e.g., both `DAY` and `SQL_TSI_DAY` are valid `unit` types for specifying a day
> > interval.  They may also be single-quoted or unquoted.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result *(in string format)*</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`TIMESTAMPADD(YEAR, 1, '2000-10-10')`</td>
>       <td>`2001-10-10`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(QUARTER, 1, '2000-11-30')`</td>
>       <td>`2001-02-28`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(MONTH, 1, '2000-01-31')`</td>
>       <td>`2000-02-29`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(WEEK, 53, '2000-01-01')`</td>
>       <td>`2001-01-06`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(DAY, 1, '2000-12-31')`</td>
>       <td>`2001-01-01`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(HOUR, 12, '2000-10-10 12:34:56')`</td>
>       <td>`2000-10-11 00:34:56.000`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(MINUTE, 1, '2000-10-10 12:34:56')`</td>
>       <td>`2000-10-10 12:35:56.000`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(SECOND, 1, '2000-12-31 23:59:59')`</td>
>       <td>`2001-01-01 00:00:00.000`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(MILLISECOND, 1, '2000-10-10 12:34:56')`</td>
>       <td>`2000-10-10 12:34:56.001`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPADD(SECOND, 1, TIME('12:34:56'))`</td>
>       <td>`12:34:57.000`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] TIMESTAMPDIFF (\[unit,] begin, end)
>
> Calculates the difference between two date/time expressions, returning the result as an
> integral difference in the units specified; more precisely, how many whole date/time
> intervals of type `unit` need to be added to  (or subtracted from) `begin` to equal
> `end` (or get as close as possible **without** going past it) using the unit types and
> the rules specified in `TIMESTAMPADD`.
>
> The default `unit` is `DAY`.
>
> Unlike `TIMEBOUNDARYDIFF`, all date/time components of both `begin` & `end` will be
> considered in the calculation, not just those that are up to the precision of `unit`.
>
> > [!NOTE]
> >
> > This *is not* symmetric with `TIMESTAMPADD` in all cases, as adding *1*
> > `MONTH` to *Mar 31st* results in *Apr 30th*, but the `TIMESTAMPDIFF` in `MONTH`
> > units between those two dates is *0*.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`TIMESTAMPDIFF(MONTH, DATETIME('2000-10-10 01:23:45.678'), DATETIME('2000-12-31 12:34:56.789'))`</td>
>       <td>`2`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPDIFF(MONTH, DATETIME('2000-03-31 01:23:45.678'), DATETIME('2000-04-30 12:34:56.789'))`</td>
>       <td>`0`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPDIFF(MONTH, DATETIME('2000-12-31 01:23:45.678'), DATETIME('2000-10-10 12:34:56.789'))`</td>
>       <td>`-2`</td>
>     </tr>
>
>     <tr>
>       <td>`TIMESTAMPDIFF(HOUR, DATETIME('2000-10-10 12:34:56.789'), TIMESTAMP(978222896678))`</td>
>       <td>`1955`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] TIMESTAMP\_DIFF(\[unit,] begin, end)
>
> Alias for `TIMESTAMPDIFF([unit,] begin, end)`

> [accordion] TIMESTAMP\_TRUNC(part, expr)
>
> Alias for `DATE_TRUNC(part, expr)`

> [accordion] UNIX\_TIMESTAMP(expr)
>
> Alias for `SECS_SINCE_EPOCH(expr)`

> [accordion] WEEK(expr)
>
> Extracts the week of the year from `expr` \[`1` - `54`]; each full week starts on
> *Sunday* (A `1` is returned for the week containing *Jan 1st*)

> [accordion] YEAR(expr)
>
> Extracts the year from `expr`; 4-digit year, A.D.

#### Date/Time Complex Conversion Functions

> [accordion] DATE\_TO\_EPOCH\_MSECS (year, month, day, hour, min, sec, msec)
>
> Converts the full date to the number of milliseconds since the epoch
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`DATE_TO_EPOCH_MSECS(2017, 06, 15, 09, 22, 15, 42)`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`1497518535042`</td>
>     </tr>
>
>     <tr>
>       <td>**Resolves To**</td>
>       <td>*Thursday, June 15, 2017 9:22:15.042 AM*</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] DATE\_TO\_EPOCH\_SECS (year, month, day, hour, min, sec)
>
> Converts the full date to the number of seconds since the epoch
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`DATE_TO_EPOCH_SECS(2017, 06, 15, 09, 22, 15)`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`1494926535`</td>
>     </tr>
>
>     <tr>
>       <td>**Resolves To**</td>
>       <td>*Thursday, June 15, 2017 9:22:15.042 AM*</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] TIMESTAMP\_FROM\_DATE\_TIME (date, time)
>
> Converts the given date and time to a composite timestamp in milliseconds
> since the epoch
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`TIMESTAMP_FROM_DATE_TIME('2017-06-15', '10:37:30')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`1497523050000`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] WEEK\_TO\_EPOCH\_MSECS (year, week\_number)
>
> Converts the year and week number to the number of milliseconds since the
> epoch; negative values are accepted
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`WEEK_TO_EPOCH_MSECS(2017,-32)`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`1463270400000`</td>
>     </tr>
>
>     <tr>
>       <td>**Resolves To**</td>
>       <td>*Sunday, May 15, 2016 12:00:00 AM*</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] WEEK\_TO\_EPOCH\_SECS (year, week\_number)
>
> Converts the year and week number to the number of seconds since the epoch.
> Negative values are accepted.  Each new week begins Sunday at midnight.
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`WEEK_TO_EPOCH_SECS(2017,-32)`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`1463270400`</td>
>     </tr>
>
>     <tr>
>       <td>**Resolves To**</td>
>       <td>*Sunday, May 15, 2016 12:00:00 AM*</td>
>     </tr>
>   </tbody>
> </table>

### Geospatial/Geometry Functions

Five types of geospatial functions are available in Kinetica:

* Scalar Functions - apply a geospatial function at the record level to WKT or
  X/Y data
* Enhanced Performance Scalar Functions - apply performance-optimized
  geospatial functions to X/Y data
* Aggregate Functions - apply a geospatial function across groups of records to
  WKT or X/Y data
* Track Functions - apply scalar & aggregate functions to
  [track-based data](https://docs.kinetica.com/content/location_intelligence/geo_objects.md#geospatial-tracks)
* H3 Functions - apply H3 gridding functions to WKT or X/Y data

> [!TIP]
>
> * Use `ST_ISVALID` to determine if a geometry object is valid. The
>   functions below work best with valid geometry objects.
> * Use the `REMOVE_NULLABLE` [function](https://docs.kinetica.com/content/concepts/expressions.md#null-expression-functions) to
>   remove any `nullable` column types that could result from calculating a
>   derived column (e.g., as in [Projections](https://docs.kinetica.com/content/concepts/projections.md)) using one of the
>   functions below.

#### Enhanced Performance Scalar Functions

The functions below all compare `x` and `y` coordinates to geometry objects
(or vice versa), thus increasing their performance in queries. Each of these
functions have a geometry-to-geometry version listed in the next section.

> [accordion] STXY\_CONTAINS(geom, x, y)
>
> Returns `1` (true) if `geom` contains the `x` and `y` coordinate, e.g. lies in the interior
> of `geom`. The coordinate cannot be on the boundary and also be contained because `geom` does not
> contain its boundary

> [accordion] STXY\_CONTAINSPROPERLY(geom, x, y)
>
> Returns `1` (true) if the `x` and `y` coordinate intersects the interior of `geom` but not
> the boundary (or exterior) because `geom` does not contain its boundary but does contain itself

> [accordion] STXY\_COVEREDBY(x, y, geom)
>
> Returns `1` (true) if the `x` and `y` coordinate is covered by `geom`

> [accordion] STXY\_COVERS(geom, x, y)
>
> Returns `1` (true) if `geom` covers the `x` and `y` coordinate

> [accordion] STXY\_DISJOINT(x, y, geom)
>
> Returns `1` (true) if the given `x` and `y` coordinate and the geometry `geom` do not
> spatially intersect.

> [accordion] STXY\_DISTANCE (x, y, geom\[, solution])
>
> Calculates the minimum distance between the given `x` and `y` coordinate and `geom` using the
> specified solution type. Solution types available:
>
> * `0` (default) - Euclidean; returns 2-D Euclidean distance
>
> * `1` - Haversine; returns minimum sphere distance in meters
>
> * `2` - Vincenty; returns minimum spheroid distance in meters, more accurate than Haversine but
>   slower performance
>
> > [!NOTE]
> >
> > If the `x` and `y` coordinate and `geom` intersect (verify using `ST_INTERSECTS`),
> > the distance will always be `0`.

> [accordion] STXY\_DWITHIN (x, y, geom, distance\[, solution])
>
> Returns `1` (true) if the `x` and `y` coordinate is within the specified `distance` from
> `geom` using the specified solution type. Solution types available:
>
> * `0` (default) - Euclidean; uses degrees to calculate distance
> * `1` - Sphere; uses meters to calculate sphere distance
> * `2` - Spheroid; uses meters to calculate spheroid distance

> [accordion] STXY\_ENVDWITHIN (x, y, geom, distance\[, solution])
>
> Returns `1` (true) if the `x` and `y` coordinate is within the specified `distance` from the
> bounding box of `geom` using the specified solution type. Solution types available:
>
> * `0` (default) - Euclidean; uses degrees to calculate distance
> * `1` - Sphere; uses meters to calculate distance

> [accordion] STXY\_ENVINTERSECTS(x, y, geom)
>
> Returns `1` (true) if the bounding box of the given geometry `geom` intersects the `x` and
> `y` coordinate.

> [accordion] STXY\_GEOHASH(x, y\[, precision])
>
> Returns a hash string representation of the given `x` and `y` coordinates with specified
> `precision` (the length of the resulting geohash string). The longer the `precision`, the more
> precise the hash is. By default, `precision` is set to `20`; the max for `precision` is `32`.
>
> See [Geohash](https://docs.kinetica.com/content/snippets/geohash) for an example.

> [accordion] STXY\_H3(x, y, resolution)
>
> Alias for `H3_XYTOCELL`; see [H3 Functions](https://docs.kinetica.com/content/location_intelligence/geo_functions.md#geo-functions-h3).

> [accordion] STXY\_INTERSECTION(x, y, geom)
>
> Returns the shared portion between the `x` and `y` coordinate and the given geometry `geom`,
> i.e. the point itself.

> [accordion] STXY\_INTERSECTS(x, y, geom)
>
> Returns `1` (true) if the `x` and `y` coordinate and `geom` intersect in 2-D.

> [accordion] STXY\_TOUCHES(x, y, geom)
>
> Returns `1` (true) if the `x` and `y` coordinate and geometry `geom` have at least one point
> in common but their interiors do not intersect. If `geom` is a GEOMETRYCOLLECTION, a `0` is
> returned regardless if the point and geometry touch

> [accordion] STXY\_WITHIN(x, y, geom)
>
> Returns `1` (true) if the `x` and `y` coordinate is completely inside the `geom` geometry
> i.e., not on the boundary

#### Scalar Functions

> [accordion] DIST(x1, y1, x2, y2)
>
> Computes the Euclidean distance (in degrees), i.e. `SQRT( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) )`.

> [accordion] GEODIST(lon1, lat1, lon2, lat2)
>
> Computes the geographic great-circle distance (in meters) between two lat/lon points.

> [accordion] GEOHASH\_DECODE\_LATITUDE(geohash)
>
> Decodes a given `geohash` and returns the latitude value for the given hash string. Supports a
> maximum geohash character length of *16*.

> [accordion] GEOHASH\_DECODE\_LONGITUDE(geohash)
>
> Decodes a given `geohash` and returns the longitude value for the given hash string. Supports a
> maximum geohash character length of *16*.

> [accordion] GEOHASH\_ENCODE(lat, lon, precision)
>
> Encodes a given coordinate pair and returns a hash string with a given `precision`. The maximum `precision` is *15*.

> [accordion] GEOMETRY(wkt)
>
> Alias for `ST_GEOMFROMTEXT(wkt)`

> [accordion] ST\_ADDPOINT (linestring, point\[, position])
>
> Adds a given `point` geometry to the given `linestring` geometry at the specified
> `position`, which is a 0-based index.  If no `position` is specified, the point will be added to the end.

> [accordion] ST\_ALMOSTEQUALS (geom1, geom2\[, decimal])
>
> Returns `1` (true) if given geometries, `geom1` and `geom2`, are almost spatially equal within
> the given amount of `decimal` scale. Note that geometries will still be considered equal if the
> decimal scale for the geometries is within a half order of magnitude of each other; e.g., if
> `decimal` is set to 2, then `POINT(63.4 123.45)` and `POINT(63.4 123.454)` are equal, but
> `POINT(63.4 123.45)` and `POINT(63.4 123.459)` are *not* equal. The geometry types must match to be
> considered equal.
>
> If no `decimal` scale is specified, a default scale of *6* will be applied.

> [accordion] ST\_AREA(geom\[, solution])
>
> Returns the area of the given geometry `geom` if it is a POLYGON or MULTIPOLYGON using the
> specified solution type. Returns `0` if the input geometry type is (MULTI)POINT or
> (MULTI)LINESTRING. Solution types available:
>
> * `0` (default) - 2D Euclidean area
> * `1` - curved surface area on a sphere in square meters
> * `2` - curved surface area on a spheroid in square meters

> [accordion] ST\_AZIMUTH(geom1, geom2)
>
> Returns the azimuth in radians defined by the segment between two POINTs, `geom1` and `geom2`.
> Returns a `null` if the input geometry type is MULTIPOINT, (MULTI)LINESTRING, or (MULTI)POLYGON.

> [accordion] ST\_BOUNDARY(geom)
>
> Returns the closure of the combinatorial boundary of a given geometry `geom`. Returns an empty
> geometry if `geom` is an empty geometry. Returns a `null` if `geom` is a GEOMETRYCOLLECTION

> [accordion] ST\_BOUNDINGDIAGONAL(geom)
>
> Returns the diagonal of the given geometry's (`geom`) bounding box.

> [accordion] ST\_BUFFER (geom, radius\[, style\[, solution]])
>
> Returns a geometry that represents all points whose distance from the given geometry `geom` is
> less than or equal to the given distance `radius`. The `radius` units can be specified by the
> `solution` type (default is in degrees) and the `radius` is created in the provided `style`.
> The `style` options are specified as a list of blank-separated key-value pairs, e.g.,
> `'quad_segs=8 endcap=round'`. If an empty `style` list (`''`) is provided, the default settings
> will be used. The `style` parameter must be specified to provide a `solution` type.
>
> Available `style` options:
>
> * `quad_segs` - the number of segments used to approximate a quarter circle (default is `8`)
> * `endcap` - the endcap style of the buffer (default is `round`); options are `round`,
>   `flat` (or `butt`), and `square`
> * `join` - the join style of the buffer (default is `round`); options are `round`, `mitre`
>   (or `miter`), and `bevel`
> * `mitre_limit` - the mitre ratio limit expressed as a floating-point number (`miter_limit` is
>   also acceptable)
>
> Available `solution` types:
>
> * `0` (default) - 2D Euclidean radius distance in degrees
>
> * `1` - curved surface radius distance on a sphere in meters
>
> * `2` - curved surface radius distance on a spheroid in meters
>
> > [!TIP]
> >
> > To create a 5-meter buffer around `geom` using the default styles:
> > `ST_BUFFER(geom, 5, '', 1)`. To create a 5-foot (converting feet to meters) buffer
> > around `geom` using the following styles:
> > `ST_BUFFER(geom, 5*0.3048,'quad_segs=4 endcap=flat', 1)`

> [accordion] ST\_BUFFERBYCOMPONENT (geom, radius\[, style\[, solution]])
>
> Returns a buffered geometry similar to the output of `ST_BUFFER` using the same parameters. The only
> difference is the buffered geometry is calculated by independently buffering each individual component
> and then the buffered components are dissolved (i.e. unioned) together to produce the final output. This
> can produce very similar (but not identical) results to `ST_BUFFER` but will often run much faster.

> [accordion] ST\_CENTROID(geom)
>
> Calculates the center of the given geometry `geom` as a POINT. For (MULTI)POINTs, the center is
> calculated as the average of the input coordinates. For (MULTI)LINESTRINGs, the center is calculated
> as the weighted length of each given LINESTRING. For (MULTI)POLYGONs, the center is calculated as
> the weighted area of each given POLYGON. If `geom` is an empty geometry, an empty
> GEOMETRYCOLLECTION is returned

> [accordion] ST\_CLIP(geom1, geom2)
>
> Returns the geometry shared between given geometries `geom1` and `geom2`

> [accordion] ST\_CLOSESTPOINT (geom1, geom2\[, solution])
>
> Calculates the 2-D `POINT` in `geom1` that is closest to `geom2` using the specified solution
> type. If `geom1` or `geom2` is empty, a `null` is returned. Solution types available:
>
> * `0` (default) - Euclidean; calculates the closest point using 2-D Euclidean distance
> * `1` - Haversine; calculates the closest point using sphere distance in meters
> * `2` - Vincenty; returns minimum spheroid distance in meters, more accurate than Haversine but
>   slower performance

> [accordion] ST\_COLLECT(geom1, geom2)
>
> Returns a MULTI\* or GEOMETRYCOLLECTION comprising `geom1` and `geom2`. If `geom1` and `geom2`
> are the same, singular geometry type, a MULTI\* is returned, e.g., if `geom1` and `geom2` are both
> POINTs (empty or no), a MULTIPOINT is returned. If `geom1` and `geom2` are neither the same type
> nor singular geometries, a GEOMETRYCOLLECTION is returned.

> [accordion] ST\_COLLECTIONEXTRACT (collection, type)
>
> Returns only the specified `type` from the given geometry `collection`. Type is a number that
> maps to the following:
>
> * `1` = `POINT`
> * `2` = `LINESTRING`
> * `3` = `POLYGON`

> [accordion] ST\_COLLECTIONHOMOGENIZE(collection)
>
> Returns the simplest form of the given `collection`, e.g., a collection with a single POINT will
> be returned as `POINT(x y)`, and a collection with multiple individual points will be returned as a
> MULTIPOINT.

> [accordion] ST\_CONCAVEHULL (geom, target\_percent\[, allow\_holes])
>
> Returns a potentially concave geometry that encloses all geometries found in the given `geom` set.
> Use `target_percent` (values between 0 and 1) to determine the percent of area of a convex hull the
> concave hull will attempt to fill; `1` will return the same geometry as an `ST_CONVEXHULL`
> operation. Set `allow_holes` to `1` (true) to allow holes in the resulting geometry; default
> value is `0` (false). Note that `allow_holes` is independent of the area of `target_percent`.

> [accordion] ST\_CONTAINS(geom1, geom2)
>
> Returns `1` (true) if no points of `geom2` lie in the exterior of `geom1` and at least one
> point of `geom2` lies in the interior of `geom1`. Note that `geom1` does not contain its
> boundary but does contain itself.

> [accordion] ST\_CONTAINSPROPERLY(geom1, geom2)
>
> Returns `1` (true) if `geom2` intersects the interior of `geom1` but not the boundary
> (or exterior). Note that `geom1` does not contain its boundary but does contain itself.

> [accordion] ST\_CONVEXHULL(geom)
>
> Returns the minimum convex geometry that encloses all geometries in the given `geom` set.

> [accordion] ST\_COORDDIM(geom)
>
> Returns the coordinate dimension of the given `geom`, e.g., a geometry with `x`, `y`, and `z`
> coordinates would return `3`.

> [accordion] ST\_COVEREDBY(geom1, geom2)
>
> Returns `1` (true) if no point in `geom1` is outside `geom2`.

> [accordion] ST\_COVERS(geom1, geom2)
>
> Returns `1` (true) if no point in `geom2` is outside `geom1`.

> [accordion] ST\_CROSSES(geom1, geom2)
>
> Returns `1` (true) if the given geometries, `geom1` and `geom2`, spatially cross, meaning some
> but not all interior points in common. If `geom1` and/or `geom2` are a GEOMETRYCOLLECTION, a
> `0` is returned regardless of if the two geometries cross

> [accordion] ST\_DIFFERENCE(geom1, geom2)
>
> Returns a geometry that represents the part of `geom1` that does not intersect with `geom2`.

> [accordion] ST\_DIMENSION(geom)
>
> Returns the dimension of the given geometry `geom`, which is less than or equal to the coordinate
> dimension. If `geom` is a single geometry, a `0` is for `POINT`, a `1` is for `LINESTRING`,
> and a `2` is for `POLYGON`. If `geom` is a collection, it will return the largest dimension from
> the collection. If `geom` is empty, `0` is returned.

> [accordion] ST\_DISJOINT(geom1, geom2)
>
> Returns `1` (true) if the given geometries, `geom1` and `geom2`, do not spatially intersect.

> [accordion] ST\_DISTANCE(geom1, geom2\[, solution])
>
> Calculates the minimum distance between the given geometries, `geom1` and `geom2`, using the
> specified solution type. Solution types available:
>
> * `0` (default) - Euclidean; returns 2-D Euclidean distance
>
> * `1` - Haversine; returns minimum sphere distance in meters
>
> * `2` - Vincenty; returns minimum spheroid distance in meters, more accurate than Haversine but
>   slower performance
>
> > [!NOTE]
> >
> > If `geom1` and `geom2` intersect (verify using `ST_INTERSECTS`), the distance will
> > always be `0`.

> [accordion] ST\_DISTANCEPOINTS (x1, y1, x2, y2\[, solution])
>
> Calculates the minimum distance between the given points, `x1, y1` and `x2, y2`, using the
> specified solution type. Solution types available:
>
> * `0` (default) - Euclidean; returns 2-D Euclidean distance
> * `1` - Haversine; returns minimum sphere distance in meters
> * `2` - Vincenty; returns minimum spheroid distance in meters, more accurate than Haversine but
>   slower performance

> [accordion] ST\_DFULLYWITHIN (geom1, geom2, distance\[, solution])
>
> Returns `1` (true) if the maximum distance between geometries `geom1` and `geom2` is less than
> or equal to the specified `distance` of each other using the specified solution type. If `geom1`
> or `geom2` is `null`, `0` (false) is returned. Solution types available:
>
> * `0` (default) - Euclidean; uses degrees to calculate distance
> * `1` - Sphere; uses meters to calculate distance
> * `2` - Spheroid; uses meters to calculate distance, more accurate than sphere but slower
>   performance

> [accordion] ST\_DWITHIN (geom1, geom2, distance\[, solution])
>
> Returns `1` (true) if the minimum distance between geometries `geom1` and `geom2` is within the
> specified `distance` of each other using the specified solution type. Solution types available:
>
> * `0` (default) - Euclidean; uses degrees to calculate distance
> * `1` - Sphere; uses meters to calculate distance
> * `2` - Spheroid; uses meters to calculate distance, more accurate than sphere but slower
>   performance

> [accordion] ST\_ELLIPSE(x, y, height, width)
>
> Returns an ellipse using the following values:
>
> * `x` - the x coordinate or longitude used to center the ellipse
> * `y` - the y coordinate or latitude used to center the ellipse
> * `height` - the height of the ellipse (in degrees)
> * `width` - the width of the ellipse (in degrees)

> [accordion] ST\_ENDPOINT(geom)
>
> Returns the last point of the given `geom` as a POINT if it's a LINESTRING.  If `geom` is not
> a LINESTRING, `null` is returned.

> [accordion] ST\_ENVDWITHIN (geom1, geom2, distance\[, solution])
>
> Returns `1` (true) if `geom1` is within the specified `distance` of the bounding box of
> `geom2` using the specified solution type. Solution types available:
>
> * `0` (default) - Euclidean; uses degrees to calculate distance
> * `1` - Sphere; uses meters to calculate distance

> [accordion] ST\_ENVELOPE(geom)
>
> Returns the bounding box of a given geometry `geom`.

> [accordion] ST\_ENVINTERSECTS(geom1, geom2)
>
> Returns `1` (true) if the bounding box of the given geometries, `geom1` and `geom2`, intersect.

> [accordion] ST\_EQUALS(geom1, geom2)
>
> Returns `1` (true) if the given geometries, `geom1` and `geom2`, are spatially equal. Note that
> order does not matter.

> [accordion] ST\_EQUALSEXACT (geom1, geom2\[, tolerance])
>
> Returns `1` (true) if the given geometries, `geom1` and `geom2`, are almost spatially equal
> within some given `tolerance`. If the values within the given geometries are within the
> `tolerance` value of each other, they're considered equal, e.g., if `tolerance` is 2,
> POINT(1 1) and POINT(1 3) are considered equal, but POINT(1 1) and POINT(1 3.1) are not. Note that
> the geometry types have to match for them to be considered equal.  The default `tolerance` is *0*,
> which makes this function effectively equivalent to `ST_EQUALS(geom1, geom2)` in the default case.

> [accordion] ST\_ERASE(geom1, geom2)
>
> Returns the result of erasing a portion of `geom1` equal to the size of `geom2`.

> [accordion] ST\_EXPAND(geom, units)
>
> Returns the bounding box expanded in all directions by the given `units` of the given `geom`. The
> expansion can also be defined for separate directions by providing separate parameters for each
> direction, e.g., `ST_EXPAND(geom, unitsx, unitsy, unitsz, unitsm)`.

> [accordion] ST\_EXPANDBYRATE(geom, rate)
>
> Returns the bounding box expanded by a given `rate` (a ratio of width and height) for the given
> geometry `geom`. The `rate` must be between 0 and 1.

> [accordion] ST\_EXTERIORRING(geom)
>
> Returns a LINESTRING representing the exterior ring of the given POLYGON `geom`

> [accordion] ST\_FORCE2D(geom)
>
> Returns the 2-dimensional version (e.g., X and Y coordinates) of `geom`, the provided geometry or
> set of geometries (e.g., via GEOMETRYCOLLECTION or WKT column name).

> [accordion] ST\_FORCE3D(geom\[, z])
>
> Returns the 3-dimensional version (e.g., X, Y, and Z coordinates) of `geom`, a provided geometry or
> set of geometries (e.g., via GEOMETRYCOLLECTION or WKT column name), using `z` as the geometry's
> new z-value. The provided z-values can also be derived from a numeric column. If no `z` is provided,
> a `0` will be applied.
>
> > [!NOTE]
> >
> > If a WKT column is provided for `geom` and a numeric column is provided for `z`, the z
> > values will be matched to the provided geometries by row in the source table. If a singular
> > geometry is provided for `geom` and a column is provided for `z`, three-dimensional
> > versions of the provided geometry will be returned for each z value found in the provided
> > `z` column. If columns are provided for both `geom` and `z` and nulls are present in
> > either column, the row containing null values will be skipped in the results.

> [accordion] ST\_GENERATEPOINTS(geom, num)
>
> Creates a MULTIPOINT containing a number `num` of randomly generated points within the boundary of
> `geom`.

> [accordion] ST\_GEOHASH(geom\[, precision])
>
> Returns a hash string representation of the given geometry `geom` with specified `precision`
> (the length of the resulting geohash string). The longer the `precision`, the more precise the hash is. By
> default, `precision` is set to `20`; the max for `precision` is `32`. Returns `null` if
> `geom` is an empty geometry.
>
> See [Geohash](https://docs.kinetica.com/content/snippets/geohash) for an example.
>
> > [!NOTE]
> >
> > The value returned will *not* be a geohash of the exact geometry but a geohash of the
> > centroid of the given geometry

> [accordion] ST\_GEOMETRYFROMTEXT(wkt)
>
> Alias for `ST_GEOMFROMTEXT(wkt)`

> [accordion] ST\_GEOMETRYN(geom, index)
>
> Returns the `index` geometry back from the given `geom` geometry. The `index` starts from 1 and goes to
> the number of geometries in `geom`.

> [accordion] ST\_GEOMETRYTYPE(geom)
>
> Returns the type of geometry from the given `geom`.

> [accordion] ST\_GEOMETRYTYPEID(geom)
>
> Returns the type ID of from `geom`. Type and ID mappings:
>
> * POINT = 0
> * LINESTRING = 1
> * POLYGON = 3
> * MULTIPOINT = 4
> * MULTILINESTRING = 5
> * MULTIPOLYGON = 6
> * GEOMETRYCOLLECTION = 7

> [accordion] ST\_GEOMFROMGEOHASH (geohash\[, precision])
>
> Returns a POLYGON boundary box using the given `geohash` with a precision set by the integer
> `precision`. If `precision` is specified, the function will use as many characters in the hash
> equal to `precision` to create the geometry. If no `precision` is specified, the full length of
> the `geohash` is used.
>
> See [Geohash](https://docs.kinetica.com/content/snippets/geohash) for an example.

> [accordion] ST\_GEOMFROMH3(h3\_index)
>
> Alias for `H3_CELLTOBOUNDARY`; see [H3 Functions](https://docs.kinetica.com/content/location_intelligence/geo_functions.md#geo-functions-h3).

> [accordion] ST\_GEOMFROMTEXT(wkt)
>
> Returns a geometry from the given Well-Known text representation `wkt`. Note that this function is
> only compatible with constants.

> [accordion] ST\_H3(wkt, resolution)
>
> Alias for `H3_GEOMTOCELL`; see [H3 Functions](https://docs.kinetica.com/content/location_intelligence/geo_functions.md#geo-functions-h3).

> [accordion] ST\_HEXGRID (xmin, ymin, xmax, ymax, cell\_side\[, limit])
>
> Creates a MULTIPOLYGON containing a grid of hexagons between given minimum and maximum points of a
> bounding box. The minimum point cannot be greater than or equal to the maximum point. The size (in
> meters) of the individual hexagons' sides is determined by `cell_side`. The `cell_side` cannot be
> greater than the width or height of the bounding box. The maximum number of cells that can be
> produced is determined by `limit`, a positive integer. Supported values for `limit`:
>
> * `-1` - No limit to the number of cells generated (effectively limited by system memory)
> * `0` (default) - 100 million cells
> * `<n>` - Custom limit of `n` cells
>
> If the custom limit request specifies more cells (based on the bounding box and the `cell_side`)
> than the system limit, a `null` is returned.

> [accordion] ST\_INTERIORRINGN(geom, n)
>
> Returns the `n`-th interior LINESTRING ring of the POLYGON `geom`. If `geom` is not a POLYGON
> or the given `n` is out of range, a `null` is returned. The index begins at 1

> [accordion] ST\_INTERSECTION(geom1, geom2)
>
> Returns the shared portion between given geometries `geom1` and `geom2`

> [accordion] ST\_INTERSECTS(geom1, geom2)
>
> Returns `1` (true) if the given geometries, `geom1` and `geom2`, intersect in 2-D

> [accordion] ST\_ISCLOSED(geom)
>
> Returns `1` (true) if the given geometry's (`geom`) start and end points coincide

> [accordion] ST\_ISCOLLECTION(geom)
>
> Returns `1` (true) if `geom` is a collection, e.g., GEOMETRYCOLLECTION, MULTIPOINT,
> MULTILINESTRING, etc.

> [accordion] ST\_ISEMPTY(geom)
>
> Returns `1` (true) if `geom` is empty

> [accordion] ST\_ISRING(geom)
>
> Returns `1` (true) if LINESTRING `geom` is both closed (per `ST_ISCLOSED`) and "simple"
> (per `ST_ISSIMPLE`). Returns `0` if `geom` is not a LINESTRING

> [accordion] ST\_ISSIMPLE(geom)
>
> Returns `1` (true) if `geom` has no anomalous geometric points, e.g., self-intersection or
> self-tangency

> [accordion] ST\_ISVALID(geom)
>
> Returns `1` (true) if `geom` (typically a \[MULTI]POLYGON) is well formed. A POLYGON is valid if
> its rings do not cross, and its boundary intersects only at POINTs (not along a line). The POLYGON must
> also not have dangling LINESTRINGs. A MULTIPOLYGON is valid if all of its elements are also valid, and
> the interior rings of those elements do not intersect. Each element's boundaries may touch but only
> at POINTs (not along a line).  `ST_MAKEVALID(geom)` can be used to help correct invalid geometries.

> [accordion] ST\_ISVALIDREASON(geom)
>
> Returns `Valid Geometry` if `geom` is well formed, according to `ST_ISVALID(geom)`; otherwise,
> returns the reason `geom` is determined to be malformed.  `ST_MAKEVALID(geom)` can be used to
> help correct invalid geometries.
>
> Example:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`ST_ISVALIDREASON('POLYGON((-1 0, 1 0, 1 1, -1 -1))')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`Self-intersection[0 0]`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] ST\_LENGTH(geom\[, solution])
>
> Returns the length of the geometry if it is a LINESTRING or MULTILINESTRING. Returns `0` if
> another type of geometry, e.g., POINT, MULTIPOINT, etc. GEOMETRYCOLLECTIONs are
> also supported but the aforementioned type limitation still applies; the collection will be
> recursively searched for LINESTRINGs and MULTILINESTRINGs and the summation of all supported geometry
> types is returned (unsupported types are ignored). Solution types available:
>
> * `0` (default) - 2D Euclidean length
> * `1` - length on a sphere in meters
> * `2` - length on a spheroid in meters

> [accordion] ST\_LINEFROMMULTIPOINT(geom)
>
> Creates a LINESTRING from `geom` if it is a MULTIPOINT. Returns `null` if `geom` is not a
> MULTIPOINT

> [accordion] ST\_LINEINTERPOLATEPOINT(geom, frac)
>
> Returns a POINT on the LINESTRING `geom` that is the `frac` fraction of the distance along the line. If `geom` is either
> empty or **not** a LINESTRING, `null` is returned

> [accordion] ST\_LINELOCATEPOINT(linestring, point)
>
> Returns the location of the closest point in the given `linestring` to the given `point` as a
> value between `0` and `1`. The return value is a fraction of the total `linestring` length.

> [accordion] ST\_LINEMERGE(geom)
>
> Returns a LINESTRING or MULTILINESTRING from a given `geom`. If `geom` is a MULTILINESTRING
> comprising LINESTRINGs with shared endpoints, a contiguous LINESTRING is returned. If `geom` is a
> LINESTRING or a MULTILINESTRING comprising LINESTRINGS without shared endpoints, `geom` is returned
> If `geom` is an empty (MULTI)LINESTRING or a (MULTI)POINT or (MULTI)POLYGON, an empty
> GEOMETRYCOLLECTION is returned.

> [accordion] ST\_LINESUBSTRING (geom, start\_frac, end\_frac)
>
> Returns the fraction of a given `geom` LINESTRING from the point that is the `start_frac` fraction of the distance along
> the line to the point that is the `end_frac` fraction of the distance along the line.
>
> For example, given `LINESTRING(1 1, 2 2, 3 3)` a `start_fraction` of `0` and an `end_fraction` of `0.25` would yield
> the first quarter of the given LINESTRING, or `LINESTRING(1 1, 1.5 1.5)`.
>
> Returns `null` in the following cases:
>
> * input geometry is (MULTI)POINT, MULTILINESTRING, or (MULTI)POLYGON
> * `start_frac` is greater than `end_frac`
> * `start_frac` or `end_frac` are not between `0` & `1`, inclusive

> [accordion] ST\_LONGESTLINE (geom1, geom2\[, solution])
>
> Returns the LINESTRING that represents the longest line of points between the two geometries. If
> multiple longest lines are found, only the first line found is returned. If `geom1` or `geom2` is
> empty, `null` is returned. Solution types available:
>
> * `0` (default) - Euclidean; uses degrees to calculate the longest line
> * `1` - Sphere; uses meters to calculate the longest line
> * `2` - Spheroid; uses meters to calculate the longest line, more accurate than sphere but slower
>   performance

> [accordion] ST\_MAKEENVELOPE (xmin, ymin, xmax, ymax)
>
> Creates a rectangular POLYGON from the given min and max parameters

> [accordion] ST\_MAKELINE(geom\[, geom2])
>
> Creates a LINESTRING from `geom` if it is a MULTIPOINT. If `geom` is a POINT, there must be at
> least one other POINT to construct a LINESTRING. If `geom` is a LINESTRING, it must have at least
> two points. Returns `null` if `geom` is not a POINT, MULTIPOINT, or LINESTRING
>
> > [!NOTE]
> >
> > This function can be rather costly in terms of performance

> [accordion] ST\_MAKEPOINT(x, y)
>
> Creates a POINT at the given coordinate
>
> > [!NOTE]
> >
> > This function can be rather costly in terms of performance

> [accordion] ST\_MAKEPOLYGON(geom)
>
> Creates a POLYGON from `geom`. Inputs must be closed LINESTRINGs
>
> > [!NOTE]
> >
> > This function can be rather costly in terms of performance

> [accordion] ST\_MAKETRIANGLE2D (x1, y1, x2, y2, x3, y3)
>
> Creates a closed 2-D POLYGON with three vertices

> [accordion] ST\_MAKETRIANGLE3D (x1, y1, z1, x2, y2, z2, x3, y3, z3)
>
> Creates a closed 3-D POLYGON with three vertices

> [accordion] ST\_MAKEVALID(geom\[, options])
>
> Attempts to convert `geom` into a valid geometry when it is malformed, as determined by
> `ST_ISVALID(geom)`.  Returns `geom` if it is a valid geometry already.  The method used to convert
> invalid geometries into valid ones can be specified in `options` as a space-separated string of
> `x=y` key/value pairs.  The keys and corresponding values are as follows:
>
> * `method` - the algorithm used to convert invalid geometries into valid ones; either:
>
>   * `linework` (default) - build geometry from lines extracted from `geom`
>   * `structure` - build geometry from interior & exterior rings extracted from `geom`
> * `keepcollapsed` - if using the `method` of `structure`, whether to drop portions of the
>   converted geometry that collapse to lower dimensions:
>
>   * `true` (default) - keep portions of geometry that collapse to lower dimensions
>   * `false` - don't keep portions of geometry that collapse to lower dimensions
>
> Example using default *linework* method:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`ST_MAKEVALID('POLYGON((-1 0, 1 0, 1 1, -1 -1))')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`MULTIPOLYGON (((-1 -1, -1 0, 0 0, -1 -1)), ((1 0, 0 0, 1 1, 1 0)))`</td>
>     </tr>
>   </tbody>
> </table>
>
> Example using the *structure* method without dropping collapsible parts of the converted geometry:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`ST_MAKEVALID('POLYGON((0 0, 0 0, 0 0, 0 0))', 'method=structure keepcollapsed=true')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`POINT (0 0)`</td>
>     </tr>
>   </tbody>
> </table>
>
> Example using the *structure* method with dropping collapsible parts of the converted geometry:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`ST_MAKEVALID('POLYGON((0 0, 0 0, 0 0, 0 0))', 'method=structure keepcollapsed=false')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`POLYGON EMPTY`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] ST\_MAXDISTANCE (geom1, geom2\[, solution])
>
> Returns the maximum distance between the given `geom1` and `geom2` geometries using the specified
> solution type. If `geom1` or `geom2` is empty, `null` is returned. Solution types available:
>
> * `0` (default) - returns maximum 2-D Euclidean distance
> * `1` - Sphere; returns maximum distance in meters
> * `2` - Spheroid; returns maximum distance in meters, more accurate than sphere but slower
>   performance

> [accordion] ST\_MAXX(geom)
>
> Returns the maximum x coordinate of a bounding box for the given `geom` geometry. This function
> works for 2-D and 3-D geometries.

> [accordion] ST\_MAXY(geom)
>
> Returns the maximum y coordinate of a bounding box for the given `geom` geometry. This function
> works for 2-D and 3-D geometries.

> [accordion] ST\_MAXZ(geom)
>
> Returns the maximum z coordinate of a bounding box for the given `geom` geometry. This function
> works for 2-D and 3-D geometries.

> [accordion] ST\_MINX(geom)
>
> Returns the minimum x coordinate of a bounding box for the given `geom` geometry. This function
> works for 2-D and 3-D geometries.

> [accordion] ST\_MINY(geom)
>
> Returns the minimum y coordinate of a bounding box for the given `geom` geometry. This function
> works for 2-D and 3-D geometries.

> [accordion] ST\_MINZ(geom)
>
> Returns the minimum z coordinate of a bounding box for the given `geom` geometry. This function
> works for 2-D and 3-D geometries.

> [accordion] ST\_MULTI(geom)
>
> Returns `geom` as a MULTI- geometry, e.g., a POINT would return a MULTIPOINT.

> [accordion] ST\_MULTIPLERINGBUFFERS (geom, distance\[, outside])
>
> Creates multiple buffers at specified `distance` around the given `geom` geometry. Multiple
> distances are specified as comma-separated values in an array, e.g., `[10,20,30]`. Valid values for
> `outside` are:
>
> * `FULL` - indicates that buffers will overlap or cover the given `geom` geometry. This is the
>   default.
> * `OUTSIDE_ONLY` - indicates that buffers will be rings around the given `geom` geometry.

> [accordion] ST\_NDIMS(geom)
>
> Returns the number of dimensions in `geom`.  For X,Y data, this will return 2; if a Z component is
> present, it will return 3.

> [accordion] ST\_NEAR(geom1, geom2)
>
> Returns the portion of `geom2` that is closest to `geom1`. If `geom2` is a singular geometry
> object (e.g., POINT, LINESTRING, POLYGON), `geom2` will be returned. If `geom2` a multi-geometry,
> e.g., MULTIPOINT, MULTILINESTRING, etc., the nearest singular geometry in `geom2` will be
> returned.

> [accordion] ST\_NORMALIZE(geom)
>
> Returns `geom` in its normalized (canonical) form, which may rearrange the points in lexicographical
> order.

> [accordion] ST\_NPOINTS(geom)
>
> Returns the number of points (vertices) in `geom`.

> [accordion] ST\_NRINGS(geom)
>
> Returns the total number of rings (including interior rings) in `geom`.  For non-polygonal geometries,
> it will return 0. For MULTIPOLYGONs, it will return the total number of rings across all components.

> [accordion] ST\_NUMGEOMETRIES(geom)
>
> If `geom` is a collection or MULTI- geometry, returns the number of geometries. If `geom` is a
> single geometry, returns 1.

> [accordion] ST\_NUMINTERIORRINGS(geom)
>
> Returns the number of interior rings if `geom` is a POLYGON. Returns `null` if `geom` is
> anything else.

> [accordion] ST\_NUMPOINTS(geom)
>
> Returns the number of points in the `geom` LINESTRING. Returns `null` if `geom` is not a
> LINESTRING.

> [accordion] ST\_OVERLAPS(geom1, geom2)
>
> Returns `1` (true) if given geometries `geom1` and `geom2` share space. If `geom1` and/or
> `geom2` are a GEOMETRYCOLLECTION, a `0` is returned regardless of if the two geometries overlap

> [accordion] ST\_PARTITION(geom\[, threshold])
>
> Returns a MULTIPOLYGON representing the given `geom` partitioned into a number of POLYGONs with a
> maximum number of vertices equal to the given `threshold`. Minimum value for `threshold` is
> `10`; default value is `10000`. If `geom` is not a POLYGON or MULTIPOLYGON, `geom` is
> returned. If the number of vertices in `geom` is less than the `threshold`, `geom` is returned.

> [accordion] ST\_PERIMETER(geom\[, solution])
>
> Returns the perimeter of the geometry if it is a POLYGON or MULTIPOLYGON. Returns `0` if another
> type of geometry, e.g., POINT, MULTIPOINT, LINESTRING, or MULTILINESTRING. GEOMETRYCOLLECTIONs are
> also supported but the aforementioned type limitation still applies; the collection will be
> recursively searched for POLYGONs and MULTIPOLYGONs and the summation of all supported geometry types
> is returned (unsupported types are ignored). Solution types available:
>
> * `0` (default) - 2D Euclidean length
> * `1` - length on a sphere in meters
> * `2` - length on a spheroid in meters

> [accordion] ST\_POINT(x, y)
>
> Returns a POINT with the given `x` and `y` coordinates.

> [accordion] ST\_POINTFROMGEOHASH (geohash\[, precision])
>
> Returns a POINT using the given `geohash` with a precision set by the integer `precision`. If
> `precision` is specified, the function will use as many characters in the hash equal to
> `precision` to create the geometry. If no `precision` is specified, the full length of
> the `geohash` is used.
>
> > [!NOTE]
> >
> > The POINT returned represents the center of the bounding box of the geohash

> [accordion] ST\_POINTGRID (xmin, ymin, xmax, ymax, cell\_side\[, limit])
>
> Creates a MULTIPOLYGON containing a square-shaped grid of points between given minimum and maximum
> points of a bounding box. The minimum point cannot be greater than or equal to the maximum point. The
> distance between the points (in meters) is determined by `cell_side`. The `cell_side` cannot be
> greater than the width or height of the bounding box. The maximum number of cells that can be
> produced is determined by `limit`, a positive integer. Supported values for `limit`:
>
> * `-1` - No limit to the number of cells generated (effectively limited by system memory)
> * `0` (default) - 100 million cells
> * `<n>` - Custom limit of `n` cells
>
> If the custom limit request specifies more cells (based on the bounding box and the `cell_side`)
> than the system limit, a `null` is returned.

> [accordion] ST\_POINTN(geom, n)
>
> Returns the `n`-th point in LINESTRING `geom`. Negative values are valid, but note that they are
> counted backwards from the end of `geom`. A `null` is returned if `geom` is not a LINESTRING.

> [accordion] ST\_POINTS(geom)
>
> Returns a MULTIPOINT containing all of the coordinates of `geom`.

> [accordion] ST\_PROJECT(geom, distance, azimuth)
>
> Returns a POINT projected from a start point `geom` along a geodesic calculated using `distance`
> and `azimuth`. If `geom` is **not** a POINT, `null` is returned.

> [accordion] ST\_REMOVEPOINT(geom, offset)
>
> Remove a point from LINESTRING `geom` using `offset` to skip over POINTs in the LINESTRING. The
> `offset` is 0-based.

> [accordion] ST\_REMOVEREPEATEDPOINTS (geom, tolerance)
>
> Removes points from `geom` if the point's vertices are greater than or equal to the `tolerance`
> of the previous point in the geometry's list. If `geom` is not a MULTIPOINT, MULTILINESTRING, or a
> MULTIPOLYGON, no points will be removed.

> [accordion] ST\_REVERSE(geom)
>
> Return the geometry with its coordinate order reversed.

> [accordion] ST\_ROTATE(geom, radians\[, wkt])
>
> Rotates `geom` counter-clockwise by `radians` radians.  Optionally, the rotation origin can be provided as a WKT POINT
> WKT POINT (`wkt`).  If not provided, `geom` will be rotated around *(0, 0)*.

> [accordion] ST\_ROTATE(geom, radians\[, x, y])
>
> Rotates `geom` counter-clockwise by `radians` radians.  Optionally, the rotation origin can be provided as a coordinate
> pair (`x` & `y`).  If not provided, `geom` will be rotated around *(0, 0)*.

> [accordion] ST\_SCALE(geom, wkt)
>
> Scales `geom` by multiplying its respective vertices by the corresponding *x*, *y* values in the given WKT POINT.
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`ST_SCALE('POLYGON((1 2, -2 1, -1 -2, 2 -1, 1 2))', GEOMETRY('POINT(3 5)'))`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`POLYGON ((3 10, -6 5, -3 -10, 6 -5, 3 10))`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] ST\_SCALE(geom, x, y)
>
> Scales `geom` by multiplying its respective vertices by the given `x` & `y` values.
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`ST_SCALE('POLYGON((1 2, -2 1, -1 -2, 2 -1, 1 2))', 3, 5)`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td>`POLYGON ((3 10, -6 5, -3 -10, 6 -5, 3 10))`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] ST\_SEGMENTIZE (geom, max\_segment\_size\[, solution])
>
> Returns the given `geom`, but segmentized *n* number of times depending on how the
> `max_segment_size` distance (in units based on the `solution` type) divides up the original
> geometry. The new `geom` is guaranteed to have segments that are smaller than the given
> `max_segment_size`. Note that POINTs are not able to be segmentized. Collection geometries
> (GEOMETRYCOLLECTION, MULTILINESTRING, MULTIPOINT, etc.) can be segmentized, but only the individual
> parts will be segmentized, not the collection as a whole. Solution types available:
>
> * `0` - Euclidean; uses degrees to calculate distance
> * `1` (default) - Sphere; uses meters to calculate distance

> [accordion] ST\_SETPOINT(geom1, position, geom2)
>
> Replace a point of LINESTRING `geom1` with POINT `geom2` at `position` (base 0). Negative
> values are valid, but note that they are counted backwards from the end of `geom`.

> [accordion] ST\_SHAREDPATH(geom1, geom2)
>
> Returns a collection containing paths shared by `geom1` and `geom2`.

> [accordion] ST\_SHORTESTLINE(geom1, geom2)
>
> Returns the 2-D LINESTRING that represents the shortest line of points between the two geometries. If
> multiple shortest lines are found, only the first line found is returned. If `geom1` or `geom2`
> is empty, `null` is returned

> [accordion] ST\_SIMPLIFY(geom, tolerance)
>
> Returns a simplified version of the given `geom` using an algorithm to reduce the number of points
> comprising a given geometry while attempting to best retain the original shape. The given
> `tolerance` determines how much to simplify the geometry. The higher the `tolerance`, the more
> simplified the returned geometry. Some holes might be removed and some invalid polygons (e.g.,
> self-intersecting, etc.) might be present in the returned geometry. Only (MULTI)LINESTRINGs and
> (MULTI)POLYGONs can be simplified, including those found within GEOMETRYCOLLECTIONs; any other
> geometry objects will be returned unsimplified.
>
> > [!NOTE]
> >
> > The `tolerance` should be provided in the same units as the data. As a rule of thumb,
> > a `tolerance` of `0.00001` would correspond to about one meter.

> [accordion] ST\_SIMPLIFYPRESERVETOPOLOGY (geom, tolerance)
>
> Returns a simplified version of the given `geom` using an algorithm to reduce the number of points
> comprising a given geometry while attempting to best retain the original shape. The given
> `tolerance` determines how much to simplify the geometry. The higher the `tolerance`, the more
> simplified the returned geometry. No holes will be removed and no invalid polygons (e.g.,
> self-intersecting, etc.) will be present in the returned geometry. Only (MULTI)LINESTRINGs and
> (MULTI)POLYGONs can be simplified, including those found within GEOMETRYCOLLECTIONs; any other
> geometry objects will be returned unsimplified.
>
> > [!NOTE]
> >
> > The `tolerance` should be provided in the same units as the data. As a rule of thumb,
> > a `tolerance` of `0.00001` would correspond to about one meter.

> [accordion] ST\_SNAP(geom1, geom2, tolerance)
>
> Snaps `geom1` to `geom2` within the given `tolerance`. If the `tolerance` causes `geom1`
> to not snap, the geometries will be returned unchanged.

> [accordion] ST\_SPLIT(geom1, geom2)
>
> Returns a collection of geometries resulting from the split between `geom1` and `geom2`
> geometries.

> [accordion] ST\_SQUAREGRID (xmin, ymin, xmax, ymax, cell\_side\[, limit])
>
> Creates a MULTIPOLYGON containing a grid of squares between given minimum and maximum points of a
> bounding box. The minimum point cannot be greater than or equal to the maximum point. The size (in
> meters) of the individual squares' sides is determined by `cell_side`. The `cell_side` cannot be
> greater than the width or height of the bounding box. The maximum number of cells that can be
> produced is determined by `limit`, a positive integer. Supported values for `limit`:
>
> * `-1` - No limit to the number of cells generated (effectively limited by system memory)
> * `0` (default) - 100 million cells
> * `<n>` - Custom limit of `n` cells
>
> If the custom limit request specifies more cells (based on the bounding box and the `cell_side`)
> than the system limit, a `null` is returned.

> [accordion] ST\_STARTPOINT(geom)
>
> Returns the first point of LINESTRING `geom` as a POINT. Returns `null` if `geom` is not a
> LINESTRING.

> [accordion] ST\_SYMDIFFERENCE(geom1, geom2)
>
> Returns a geometry that represents the portions of `geom1` and `geom2` geometries that do not
> intersect.

> [accordion] ST\_TOUCHES(geom1, geom2)
>
> Returns `1` (true) if the given geometries, `geom1` and `geom2`, have at least one point in
> common but their interiors do not intersect. If `geom1` and/or `geom2` are a GEOMETRYCOLLECTION,
> a `0` is returned regardless of if the two geometries touch

> [accordion] ST\_TRANSLATE (geom, deltax, deltay\[, deltaz])
>
> Translate `geom` by given offsets `deltax` and `deltay`. A z-coordinate offset can be applied
> using `deltaz`.
> intersect.

> [accordion] ST\_TRIANGLEGRID (xmin, ymin, xmax, ymax, cell\_side\[, limit])
>
> Creates a MULTIPOLYGON containing a grid of triangles between given minimum and maximum points of a
> bounding box. The minimum point cannot be greater than or equal to the maximum point. The size (in
> meters) of the individual triangles' sides is determined by `cell_side`. The `cell_side` cannot be
> greater than the width or height of the bounding box. The maximum number of cells that can be
> produced is determined by `limit`, a positive integer. Supported values for `limit`:
>
> * `-1` - No limit to the number of cells generated (effectively limited by system memory)
> * `0` (default) - 100 million cells
> * `<n>` - Custom limit of `n` cells
>
> If the custom limit request specifies more cells (based on the bounding box and the `cell_side`)
> than the system limit, a `null` is returned.

> [accordion] ST\_UNION(geom1, geom2)
>
> Returns a geometry that represents the point set union of the two given geometries, `geom1` and
> `geom2`.

> [accordion] ST\_UNIONCOLLECTION(geom)
>
> Returns a geometry that represents the point set union of a single given geometry `geom`.

> [accordion] ST\_UPDATE(geom1, geom2)
>
> Returns a geometry that is `geom1` geometry updated by `geom2` geometry

> [accordion] ST\_VORONOIPOLYGONS(geom\[, tolerance])
>
> Returns a GEOMETRYCOLLECTION containing Voronoi polygons (regions consisting of points closer to
> a vertex in `geom` than any other vertices in `geom`) calculated from the vertices in `geom`
> and the given `tolerance`. The `tolerance` determines the distance at which points will be
> considered the same.  An empty GEOMETRYCOLLECTION is returned if `geom` is an empty geometry, a
> single POINT, or a LINESTRING or POLYGON composed of equivalent vertices (e.g.,
> `POLYGON((0 0, 0 0, 0 0, 0 0))`, `LINESTRING(0 0, 0 0)`).
>
> If no `tolerance` is specified, no vertices will be considered the same; each will have its own polygon.
>
> The bounding box for the result POLYGONs extends past the four edges of the input `geom` bounding box by
> an amount that is the greater of the input bounding box's height and width.  For instance, an input `geom`
> with a *3* x *4* bounding box will result in Voronoi polygons filling a space that is *11* x *12*.

> [accordion] ST\_WITHIN(geom1, geom2)
>
> Returns `1` (true) if the `geom1` geometry is inside the `geom2` geometry. Note that as long as
> at least one point is inside of `geom2`, `geom1` is considered within `geom2` even if the rest
> of the `geom1` lies along the boundary of `geom2`

> [accordion] ST\_WKBTOWKT(geom)
>
> Returns the text form (WKT) of a geometry from the given byte form (WKB)

> [accordion] ST\_WKTTOWKB(geom)
>
> Returns the byte form (WKB) of a geometry from the given text form (WKT)

> [accordion] ST\_X(geom)
>
> Returns the X coordinate of the POINT `geom`; if the coordinate is not available, `null` is
> returned. `geom` must be a POINT.

> [accordion] ST\_XMAX(geom)
>
> Alias for `ST_MAXX()`

> [accordion] ST\_XMIN(geom)
>
> Alias for `ST_MINX()`

> [accordion] ST\_Y(geom)
>
> Returns the Y coordinate of the POINT `geom`; if the coordinate is not available, `null` is
> returned. `geom` must be a POINT.

> [accordion] ST\_YMAX(geom)
>
> Alias for `ST_MAXY()`

> [accordion] ST\_YMIN(geom)
>
> Alias for `ST_MINY()`

> [accordion] ST\_ZMAX(geom)
>
> Alias for `ST_MAXZ()`

> [accordion] ST\_ZMIN(geom)
>
> Alias for `ST_MINZ()`

#### Aggregation Functions

The following functions can be used on geospatial/geometry columns within
[aggregations](https://docs.kinetica.com/content/concepts/expressions.md#aggregate-expressions-label).

> [accordion] ST\_AGGREGATE\_COLLECT(geom)
>
> Alias for `ST_COLLECT_AGGREGATE()`

> [accordion] ST\_AGGREGATE\_INTERSECTION(geom)
>
> Alias for `ST_INTERSECTION_AGGREGATE()`

> [accordion] ST\_COLLECT\_AGGREGATE(geom)
>
> Returns a GEOMETRYCOLLECTION comprising all geometries found in the `geom` set.
> Any MULTI\* geometries will be divided into separate singular geometries, e.g.,
> MULTIPOINT((0 0), (1 1)) would be divided into POINT(0 0) and POINT(1 1) in the
> results; the same is true for elements of a GEOMETRYCOLLECTION found in `geom`,
> where a GEOMETRYCOLLECTION within the provided `geom` set will also be parsed,
> effectively flattening it and adding the individual geometries to the resulting
> GEOMETRYCOLLECTION. Any empty geometries in `geom` are ignored even if they are
> part of a GEOMETRYCOLLECTION. Any duplicate WKTs will be retained.

> [accordion] ST\_DISSOLVE(geom)
>
> Dissolves all geometries within a given set into a single geometry. Note that the
> resulting single geometry can still be a group of noncontiguous geometries but
> represented as a single group, e.g., a GEOMETRYCOLLECTION.  Best performance when
> used in conjunction with adjacent geometries.

> [accordion] ST\_DISSOLVEOVERLAPPING(geom)
>
> Dissolves all geometries within a given set into a single geometry. Note that the
> resulting single geometry can still be a group of noncontiguous geometries but
> represented as a single group, e.g., a GEOMETRYCOLLECTION.  Best performance when
> used in conjunction with overlapping geometries.

> [accordion] ST\_INTERSECTION\_AGGREGATE(geom)
>
> Returns a POLYGON or MULTIPOLYGON comprising the shared portion between all
> geometries found in the `geom` set.  Returns an empty GEOMETRYCOLLECTION if
> there is no shared portion between all geometries. Functionally equivalent to
> `ST_INTERSECTION(ST_INTERSECTION(geom1, geom2), ... geomN)`.

> [accordion] ST\_LINESTRINGFROMORDEREDPOINTS(x, y, t)
>
> Returns a LINESTRING that represents a "track" of the given points (`x`, `y`)
> ordered by the given sort column `t` (e.g., a timestamp or sequence number). If
> any of the values in the specified columns are `null`, the null "point" will be
> left out of the resulting LINESTRING. If there's only one non-null "point" in the
> source table, a POINT is returned. If there are no non-null "points" in the
> source table, a `null` is returned.

> [accordion] ST\_LINESTRINGFROMORDEREDPOINTS3D(x, y, z, t)
>
> Returns a LINESTRING that represents a "track" of the given 3D points
> (`x`, `y`, `z`) ordered by the given sort column `t` (e.g., a timestamp
> or sequence number). If any of the values in the specified columns are `null`,
> the null "point" will be left out of the resulting LINESTRING. If there's only
> one non-null "point" in the source table, a POINT is returned. If there are no
> non-null "points" in the source table, a `null` is returned.

> [accordion] ST\_POLYGONIZE(geom)
>
> Returns a GEOMETRYCOLLECTION containing POLYGONs comprising the provided
> (MULTI)LINESTRING(s). (MULTI)POINT and (MULTI)POLYGON geometries are ignored when
> calculating the resulting GEOMETRYCOLLECTION. If a valid POLYGON cannot be
> constructed from the provided (MULTI)LINESTRING(s), an empty GEOMETRYCOLLECTION
> will be returned.

#### Track Functions

The following functions are available in both SQL and the native API.

> [accordion] ST\_TRACKDURATION(\[unit,] t)
>
> Returns the total time, in the given `unit`, spanned by timestamp values in column
> `t`.  Grouping by *track* ID will return the duration per *track*.
>
> The duration can be returned in any of the following date/time units:
>
> * `YEAR`
> * `MONTH`
> * `DAY`
> * `HOUR`
> * `MINUTE`
> * `SECOND`
> * `MILLISECOND`
>
> The default `unit` is `MILLISECOND`.

> [accordion] ST\_TRACKLENGTH(lat, lon, t\[, solution])
>
> Returns the total length of the track whose position values are specified by `lat` &
> `lon` and whose ordering is determined by an ascending sort on the timestamp `t`.
> Length can be returned with any of the following solution types:
>
> <table>
>   <thead>
>     <tr>
>       <th>Type</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`0`</td>
>       <td>2D Euclidean length in degrees</td>
>     </tr>
>
>     <tr>
>       <td>`1`</td>
>       <td>(default) Length on a sphere in meters</td>
>     </tr>
>
>     <tr>
>       <td>`2`</td>
>       <td>Length on a spheroid in meters</td>
>     </tr>
>   </tbody>
> </table>

**ST\_TRACK\_DWITHIN**

The `ST_TRACK_DWITHIN` table function finds tracks that are related, within
spatial or temporal bounds (or both) to the given track(s).  The track(s) to use
as the filter criteria will be specified by the `SEARCH_*` parameters.  The
`TRACK_*` parameters specify the set of tracks to search through for a match.

> [!NOTE]
>
> This function is only available in SQL or in the native API via
> [/execute/sql](https://docs.kinetica.com/content/api/rest/execute_sql_rest.md).

The basic form of the `ST_TRACK_DWITHIN` function follows.

```sql ST_TRACK_DWITHIN Table Function Syntax theme={null}
SELECT *
FROM TABLE
(
    ST_TRACK_DWITHIN
    (
        TRACK_TABLE => INPUT_TABLE(<table name | select statement>),
        TRACK_ID_COLUMN => < '<column name>' | <column position> >,
        TRACK_X_COLUMN => < '<column name>' | <column position> >,
        TRACK_Y_COLUMN => < '<column name>' | <column position> >,
        TRACK_ORDER_COLUMN => < '<column name>' | <column position> >,
        SEARCH_TABLE => INPUT_TABLE(<table name | select statement>),
        SEARCH_ID_COLUMN => < '<column name>' | <column position> >,
        SEARCH_X_COLUMN => < '<column name>' | <column position> >,
        SEARCH_Y_COLUMN => < '<column name>' | <column position> >,
        SEARCH_ORDER_COLUMN => < '<column name>' | <column position> >,
        [
            SEARCH_XY_DISTANCE => '<spatial distance with unit>',
            SPATIAL_SOLUTION_TYPE => <solution type>,
            SEARCH_TIME_DISTANCE => '<temporal distance with unit>'
        ]
    )
)
```

> [accordion] TRACK\_TABLE
>
> Name of the table to search for tracks matching the track(s) specified in the `SEARCH_*` data set.
>
> To perform a search on the *flights* table, pass the name of the table to `INPUT_TABLE`:
>
> ```
> INPUT_TABLE(flights)
> ```
>
> To perform a search on the result of a query, pass the query to `INPUT_TABLE`:
>
> ```
> INPUT_TABLE
> (
>     SELECT * FROM flights_west
>     UNION
>     SELECT * FROM flights_east
> )
> ```

> [accordion] TRACK\_ID\_COLUMN
>
> Table to search track column, containing the unique identifier for the track to which each track point
> belongs.

> [accordion] TRACK\_X\_COLUMN
>
> Table to search track column, containing the longitude value of each track point.

> [accordion] TRACK\_Y\_COLUMN
>
> Table to search track column, containing the latitude value of each track point.

> [accordion] TRACK\_ORDER\_COLUMN
>
> Table to search track column, by which the searched track points will be sorted in ascending order.

> [accordion] SEARCH\_TABLE
>
> Name of the search criteria track table, containing the track(s) to be used as the filter criteria
> when searching for matching tracks in the `TRACK_*` data set.
>
> To match tracks from the *flights\_of\_interest* table, pass the name of the table to `INPUT_TABLE`:
>
> ```
> INPUT_TABLE(flights_of_interest)
> ```
>
> To match tracks from the result of a query, pass the query to `INPUT_TABLE`:
>
> ```
> INPUT_TABLE
> (
>     SELECT * FROM flights_of_interest_west
>     UNION
>     SELECT * FROM flights_of_interest_east
> )
> ```

> [accordion] SEARCH\_ID\_COLUMN
>
> Search criteria track column, containing the unique identifier for the track to which each track point
> belongs.

> [accordion] SEARCH\_X\_COLUMN
>
> Search criteria track column, containing the longitude value of each track point.

> [accordion] SEARCH\_Y\_COLUMN
>
> Search criteria track column, containing the latitude value of each track point.

> [accordion] SEARCH\_ORDER\_COLUMN
>
> Search criteria track column, by which the filter track points will be sorted in ascending order.

> [accordion] SEARCH\_XY\_DISTANCE
>
> The radius around the given tracks to search for matching tracks.
>
> > [!NOTE]
> >
> > This parameter is not applicable when using a `SPATIAL_SOLUTION_TYPE` of `0`.
>
> <table>
>   <thead>
>     <tr>
>       <th>Unit</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`f`</td>
>       <td>Feet</td>
>     </tr>
>
>     <tr>
>       <td>`ki`</td>
>       <td>Kilometers</td>
>     </tr>
>
>     <tr>
>       <td>`m`</td>
>       <td>(default) Meters</td>
>     </tr>
>
>     <tr>
>       <td>`mi`</td>
>       <td>Miles</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] SPATIAL\_SOLUTION\_TYPE
>
> Spatial match solution type; any of the following:
>
> <table>
>   <thead>
>     <tr>
>       <th>Type</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`0`</td>
>       <td>(default) 2D Euclidean length in degrees</td>
>     </tr>
>
>     <tr>
>       <td>`1`</td>
>       <td>Length on a sphere, returned in units specified by `SEARCH_XY_DISTANCE`</td>
>     </tr>
>
>     <tr>
>       <td>`2`</td>
>       <td>Length on a spheroid, returned in units specified by `SEARCH_XY_DISTANCE`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] SEARCH\_TIME\_DISTANCE
>
> The maximum allowable time difference between a search criteria track's point and a matched track's
> points.  The time can use any of the following suffices for units:
>
> <table>
>   <thead>
>     <tr>
>       <th>Unit</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`ms`</td>
>       <td>Milliseconds</td>
>     </tr>
>
>     <tr>
>       <td>`s`</td>
>       <td>(default) Seconds</td>
>     </tr>
>
>     <tr>
>       <td>`m`</td>
>       <td>Minutes</td>
>     </tr>
>
>     <tr>
>       <td>`h`</td>
>       <td>Hours</td>
>     </tr>
>
>     <tr>
>       <td>`d`</td>
>       <td>Days</td>
>     </tr>
>
>     <tr>
>       <td>`w`</td>
>       <td>Weeks</td>
>     </tr>
>
>     <tr>
>       <td>`months`</td>
>       <td>Months</td>
>     </tr>
>
>     <tr>
>       <td>`y`</td>
>       <td>Years</td>
>     </tr>
>   </tbody>
> </table>

To see the matches between a set of flights and a given set of flights of
interest:

```sql ST_TRACK_DWITHIN Example theme={null}
SELECT *
FROM TABLE
(
	ST_TRACK_DWITHIN
	(
		TRACK_TABLE => INPUT_TABLE(example_geospatial.flights),
		TRACK_ID_COLUMN => 'id',
		TRACK_X_COLUMN => 'lon',
		TRACK_Y_COLUMN => 'lat',
		TRACK_ORDER_COLUMN => 'flight_time',
		SEARCH_TABLE => INPUT_TABLE
						(
							SELECT id, lon, lat, flight_time
							FROM example_geospatial.flights_northwest
							UNION
							SELECT id, lon, lat, flight_time
							FROM example_geospatial.flights_northeast
						),
		SEARCH_ID_COLUMN => 1,
		SEARCH_X_COLUMN => 2,
		SEARCH_Y_COLUMN => 3,
		SEARCH_ORDER_COLUMN => 4,
		SEARCH_TIME_DISTANCE => '5m',
		SEARCH_XY_DISTANCE => '1km',
		SPATIAL_SOLUTION_TYPE => 1
	)
)
```

**ST\_TRACKINTERSECTS**

The `ST_TRACKINTERSECTS` table function finds tracks pass through the given
geofence(s).  The geofence(s) use as the filter will be specified by the
`GEOFENCE_*` parameters.  The `TRACK_*` parameters specify the set of
tracks to search through for any intersecting the geofence(s).

The result will include a record for each intersecting track & geofence pair,
with:

* a `LINESTRING` representing the full track intersecting a geofence
* a `LINESTRING` representing the geofence it intersected

> [!NOTE]
>
> This function is only available in SQL or in the native API via
> [/execute/sql](https://docs.kinetica.com/content/api/rest/execute_sql_rest.md).

The basic form of the `ST_TRACKINTERSECTS` function follows.

```sql ST_TRACKINTERSECTS Table Function Syntax theme={null}
SELECT *
FROM TABLE
(
    ST_TRACKINTERSECTS
    (
        TRACK_TABLE => INPUT_TABLE(<table name | select statement>),
        TRACK_ID_COLUMN => < '<column name>' | <column position> >,
        TRACK_X_COLUMN => < '<column name>' | <column position> >,
        TRACK_Y_COLUMN => < '<column name>' | <column position> >,
        TRACK_ORDER_COLUMN => < '<column name>' | <column position> >,
        GEOFENCE_TABLE => INPUT_TABLE(<table name | select statement>),
        GEOFENCE_ID_COLUMN => < '<column name>' | <column position> >,
        GEOFENCE_WKT_COLUMN => < '<column name>' | <column position> >
    )
)
```

> [accordion] TRACK\_TABLE
>
> Name of the table to search for tracks intersecting the geofence(s) specified in the `SEARCH_*` data
> set.
>
> To perform a search on the *flights* table, pass the name of the table to `INPUT_TABLE`:
>
> ```
> INPUT_TABLE(flights)
> ```
>
> To perform a search on the result of a query, pass the query to `INPUT_TABLE`:
>
> ```
> INPUT_TABLE
> (
>     SELECT * FROM flights_west
>     UNION
>     SELECT * FROM flights_east
> )
> ```

> [accordion] TRACK\_ID\_COLUMN
>
> Table to search track column, containing the unique identifier for the track to which each track point
> belongs.

> [accordion] TRACK\_X\_COLUMN
>
> Table to search track column, containing the longitude value of each track point.

> [accordion] TRACK\_Y\_COLUMN
>
> Table to search track column, containing the latitude value of each track point.

> [accordion] TRACK\_ORDER\_COLUMN
>
> Table to search track column, by which the searched track points will be sorted in ascending order.

> [accordion] GEOFENCE\_TABLE
>
> Name of the geofence table, containing the WKT(s) to be used as the filter criteria when searching for
> intersecting tracks in the `TRACK_*` data set.
>
> To search for tracks intersecting the geofence(s) from the *flight\_area\_of\_interest* table, pass the
> name of the geofence table to `INPUT_TABLE`:
>
> ```
> INPUT_TABLE(flight_area_of_interest)
> ```
>
> To search for tracks intersecting the geofence(s) from the result of a query, pass the query to
> `INPUT_TABLE`:
>
> ```
> INPUT_TABLE
> (
>     SELECT * FROM flight_area_of_interest_west
>     UNION
>     SELECT * FROM flight_area_of_interest_east
> )
> ```

> [accordion] GEOFENCE\_ID\_COLUMN
>
> Geofence column, containing the unique identifier for the geofence.

> [accordion] GEOFENCE\_WKT\_COLUMN
>
> Geofence column, containing the WKT bounds of the geofence.

To see the intersections between a set of flights and an area of interest:

```sql ST_TRACKINTERSECTS Example theme={null}
SELECT *
FROM TABLE
(
	ST_TRACKINTERSECTS
	(
		TRACK_TABLE =>         INPUT_TABLE(example_geospatial.flights),
		TRACK_ID_COLUMN =>     'id',
		TRACK_X_COLUMN =>      'lon',
		TRACK_Y_COLUMN =>      'lat',
		TRACK_ORDER_COLUMN =>  'flight_time',
		GEOFENCE_TABLE =>      INPUT_TABLE(example_geospatial.track_geofence),
		GEOFENCE_ID_COLUMN =>  'fence_name',
		GEOFENCE_WKT_COLUMN => 'fence_wkt'
	)
)
ORDER BY id, fence_name
```

#### H3 Functions

The functions below support various operations using the H3 geospatial indexing scheme.

> [accordion] H3\_CELLTOBOUNDARY(h3\_index)
>
> Returns a POLYGON boundary box of the H3 index identified by the given `h3_index`.
>
> See [Geohash-H3](https://docs.kinetica.com/content/snippets/geohash-h3) for an example.

> [accordion] H3\_CELLTOCENTERCHILD(h3\_index, res)
>
> Alias for `H3_CELLTOFIRSTCHILD`.

> [accordion] H3\_CELLTOCHILDN(h3\_index, res, i)
>
> Returns the H3 index corresponding to the 0-based `i` th child at resolution `res` for the given
> `h3_index`.  The value `i` should be less than the number of children returned from calling
> `H3_CELLTOCHILDRENSIZE(h3_index, res)`.

> [accordion] H3\_CELLTOCHILDPOS(h3\_index, res)
>
> Returns the position of the given `h3_index` within an ordered list of the children of the cell's
> parent at resolution `res`. This is the inverse of `H3_CHILDPOSTOCELL` (`H3_CELLTOCHILDN`).

> [accordion] H3\_CELLTOCHILDRENSIZE(h3\_index, res)
>
> Returns the number of child cells at resolution `res` for the given `h3_index`.

> [accordion] H3\_CELLTOFIRSTCHILD(h3\_index, res)
>
> Returns the H3 index corresponding to the first child at resolution `res` for the given `h3_index`.
>
> This is equivalent to `H3_CELLTOCHILDN(h3_index,res,0)`.

> [accordion] H3\_CELLTOLASTCHILD(h3\_index, res)
>
> Returns the H3 index corresponding to the last child at resolution `res` for the given `h3_index`.
>
> This is equivalent to `H3_CELLTOCHILDN(h3_index,res,H3_CELLTOCHILDRENSIZE(h3_index, res)-1)`.

> [accordion] H3\_CELLTOPARENT(h3\_index, res)
>
> Returns the H3 index corresponding to the parent cell of the given `h3_index` at resolution `res`.

> [accordion] H3\_CELLTOXY(h3\_index)
>
> Returns a WKT POINT corresponding to the centroid of the given `h3_index`.

> [accordion] H3\_CHILDPOSTOCELL(i, h3\_index, res)
>
> Alias for `H3_CELLTOCHILDN(h3_index, res, i)`.

> [accordion] H3\_GEOMTOCELL(geom, res)
>
> Returns the H3 index, similar to a geohash, for the cell containing the centroid of the geometry
> `geom` with the given resolution `res`.  The higher the resolution, the more precise the index
> is. The resolution `res` must be an integer between `0` and `15`.
>
> See [Geohash-H3](https://docs.kinetica.com/content/snippets/geohash-h3) for an example.

> [accordion] H3\_GETRESOLUTION(h3\_index)
>
> Returns the resolution of the H3 index `h3_index`.

> [accordion] H3\_GRIDDISK(h3\_index, k)
>
> Returns an array of H3 indexes within a given distance `k` from the provided H3 index `h3_index`.

> [accordion] H3\_GRIDDISKN(h3\_index, k, i)
>
> Returns the `i` <sup>th</sup> H3 index within a given distance `k` from the provided H3 index
> `h3_index`.  This function would typically be used in conjunction with `H3_NUMGRIDDISK` via iter-join.
> The value of `i` should be between `0` and the result of `H3_NUMGRIDDISK(h3_index, k)` - `1`.

> [accordion] H3\_GRIDRING(h3\_index, k)
>
> Returns an array of H3 indexes comprising a hollow ring at a distance `k` from the provided
> H3 index `h3_index`.

> [accordion] H3\_H3TOSTRING(h3\_index)
>
> Returns the string representation of the H3 index `h3_index`.
>
> > [!NOTE]
> >
> > This function is the inverse of `H3_STRINGTOH3`.

> [accordion] H3\_ISVALID(h3\_index)
>
> Returns `1` (true) if the given H3 index `h3_index` is a valid H3 index value; otherwise
> returns `0` (false).

> [accordion] H3\_LATLNGTOCELL (latitude, longitude, res)
>
> Returns the H3 index, similar to a geohash, for the cell containing the `latitude` and `longitude`
> coordinate, with the given resolution `res`.  The higher the resolution, the more precise the index
> is. The resolution `res` must be an integer between `0` and `15`.
>
> Equivalent to `H3_XYTOCELL(longitude, latitude, res)`.

> [accordion] H3\_NUMGRIDDISK(h3\_index, k)
>
> Returns the number of cells at a distance of `k` from the provided H3 index `h3_index`. This function
> would typically be used in conjunction with `H3_GRIDDISKN` via iter-join.

> [accordion] H3\_NUMPOLYGONTOCELLS(geom, res)
>
> Returns the number of cells at the given resolution `res` that are within the given geometry `geom`.
> Only polygon geometries are supported. This function would typically be used in conjunction with
> `H3_POLYGONTOCELLSN` via iter-join.

> [accordion] H3\_POLYGONTOCELLS(geom, res)
>
> Returns an array of H3 indexes at the given resolution `res` that are within the given geometry `geom`.
> Only polygon geometries are supported.

> [accordion] H3\_POLYGONTOCELLSN(geom, res, i)
>
> Returns the `i` <sup>th</sup> H3 index at the given resolution `res` that is within the given geometry
> `geom`.  Only polygon geometries are supported. This function would typically be used in conjunction with
> `H3_NUMPOLYGONTOCELLS` via iter-join. The value of `i` should be between `0` and the value returned
> from `H3_NUMPOLYGONTOCELLS(geom, res)` - `1`.

> [accordion] H3\_STRINGTOH3(h3\_string)
>
> Returns the H3 index corresponding to the string representation `h3_string`.
>
> > [!NOTE]
> >
> > This function is the inverse of `H3_H3TOSTRING`.

> [accordion] H3\_XYTOCELL(x, y, res)
>
> Returns the H3 index, similar to a geohash, for the cell containing the `x` and `y` coordinate,
> with the given resolution `res`.  The higher the resolution, the more precise the index is. The
> resolution `res` must be an integer between `0` and `15`.
>
> Equivalent to `H3_LATLNGTOCELL(y, x, res)`.
>
> See [Geohash-H3](https://docs.kinetica.com/content/snippets/geohash-h3) for an example.

### JSON Functions

#### Scalar Functions

These functions can be applied to individual *json* column values, as well as
*array* & *string* columns.  However, for some functions to work as expected,
the *array* or *string* value may need to be cast to JSON first.

> [accordion] JSON(expr)
>
> Casts the given `expr` to JSON data type
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON('[1, 2, "C"]')`</td>
>       <td>`[1,2,"C"]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON('{"A": "B", "C": {"D": 5, "F": 7}}')`</td>
>       <td>`{"A":"B","C":{"D":5,"F":7}}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON(null)`</td>
>       <td>*null*</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_ARRAY (value\[,...] \<null\_hand>)
>
> Creates a JSON array out of the given list of values.
>
> An optional `<null_hand>` parameter can be added to the end of the list to specify
> handling of *null* values, though, at present, this only exists for compatibility with
> other databases' syntax--the option will be ignored and all *null* values will be added
> to the array as *null*.  Accepted null handling options:
>
> * `NULL ON NULL`
>
> > [!NOTE]
> >
> > This function is only available in SQL or in the native API via
> > [/execute/sql](https://docs.kinetica.com/content/api/rest/execute_sql_rest.md).
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_ARRAY(1, 2, 'C')`</td>
>       <td>`[1,2,"C"]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_ARRAY(JSON('{"A": "B"}'), JSON('{"C": 4}'))`</td>
>       <td>`[{"A":"B"},{"C":4}]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_ARRAY(1, null, 'C' NULL ON NULL)`</td>
>       <td>`[1,null,"C"]`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_ARRAY\_APPEND(arr, value)
>
> Appends the given `value` to the given array `arr` of type string, array, or JSON
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_ARRAY_APPEND('[1, 2]', 'C')`</td>
>       <td>`[1,2,"C"]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_ARRAY_APPEND('{"A": "B"}', JSON('{"C": 4}'))`</td>
>       <td>`[{"A":"B"},{"C":4}]`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_ARRAY\_CONTAINS (json, path, val)
>
> Returns whether the given JSON `json` contains the primitive value `val` at the JSON
> query path, `path`
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_ARRAY_CONTAINS('[1, 2]', '$', 2)`</td>
>       <td>`true`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_ARRAY_CONTAINS('[1, 2]', '$', 'C')`</td>
>       <td>`false`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_ARRAY_CONTAINS('{"A": [2, 3]}', '$.A', 2)`</td>
>       <td>`true`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_ARRAY_CONTAINS('{"A": {"B": [3, 4]}}', '$["A"]["B"]', 4)`</td>
>       <td>`true`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_CARDINALITY(json)
>
> Alias for `JSON_LENGTH`

> [accordion] JSON\_EXISTS(json, path)
>
> Returns whether the given JSON `json` contains the JSON query path, `path`
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_EXISTS('[1, 2]', '$')`</td>
>       <td>`true`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_EXISTS('[1, 2]', '$.A')`</td>
>       <td>`false`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_EXISTS('{"A": [2, 3]}', '$.A')`</td>
>       <td>`true`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_EXISTS('{"A": {"B": 3, "D": 5}}', '$["A"]["D"]')`</td>
>       <td>`true`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_KEYS(json, path)
>
> Returns the set of keys of the JSON object at the given `path` in `json`; null, if the
> path doesn't exist or contains a non-object (non-map) value
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_KEYS('{}', '$')`</td>
>       <td>`[]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_KEYS('[1, 2]', '$.A')`</td>
>       <td>*null*</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_KEYS('{"A": [2, 3]}', '$')`</td>
>       <td>`["A"]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_KEYS('{"A": {"B": 3, "D": 5}}', '$["A"]')`</td>
>       <td>`["B","D"]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_KEYS('{"A": {"B": 3, "D": 5}}', '$["A"]["D"]')`</td>
>       <td>*null*</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_KEYS('{"A": {"B": 3, "D": {}}}', '$["A"]["D"]')`</td>
>       <td>`[]`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_LENGTH(json\[, path])
>
> Returns the number of items in the top-level object of the given `json`, or at the
> level of the optional JSON `path`
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_LENGTH('{}')`</td>
>       <td>`0`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_LENGTH('[]')`</td>
>       <td>`0`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_LENGTH('[1, 2]')`</td>
>       <td>`2`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_LENGTH('{"A": [2, 3]}')`</td>
>       <td>`1`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_LENGTH('{"A": {"B": 3}, "D": "E"}')`</td>
>       <td>`2`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_LENGTH('{"A": [2, 3]}', '$.A')`</td>
>       <td>`2`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_LENGTH('{"A": {"B": 3}, "D": "E"}', '$.A')`</td>
>       <td>`1`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_MAKE\_ARRAY(value)
>
> Creates a JSON array out of the given `value`
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_MAKE_ARRAY(1)`</td>
>       <td>`[1]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_MAKE_ARRAY(JSON_ARRAY(1,2,3))`</td>
>       <td>`[[1,2,3]]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_MAKE_ARRAY(JSON('{"A": "B"}'))`</td>
>       <td>`[{"A":"B"}]`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_OBJECT (value\[,...] \<null\_hand>)
>
> Creates a JSON map out of the given `value` set
>
> An optional `<null_hand>` parameter can be added to the end of the list to specify
> handling of *null* values, though, at present, this only exists for compatibility with
> other databases' syntax--the option will be ignored and all *null* values will be added
> to the array as *null*.  Accepted null handling options:
>
> * `NULL ON NULL`
>
> > [!NOTE]
> >
> > This function is only available in SQL or in the native API via
> > [/execute/sql](https://docs.kinetica.com/content/api/rest/execute_sql_rest.md).
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_OBJECT()`</td>
>       <td>`{}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_OBJECT('A': 2)`</td>
>       <td>`{"A":2}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_OBJECT('A' VALUE 2)`</td>
>       <td>`{"A":2}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_OBJECT(KEY 'A' VALUE 2)`</td>
>       <td>`{"A":2}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_OBJECT('A': 'B', 'C': null NULL ON NULL)`</td>
>       <td>`{"A":"B","C":null}`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_PRETTY(json)
>
> Returns a formatted version of the given `json` object
>
> Examples:
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`JSON_PRETTY('[1,2,"C"]')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td><pre>`[
>             1,
>             2,
>             "C"
>             ]`</pre></td>
>     </tr>
>   </tbody>
> </table>
>
> <table>
>   <tbody>
>     <tr>
>       <td>**Function Call**</td>
>       <td>`JSON_PRETTY('{"A": "B", "C": {"D": 5, "F": 7}}')`</td>
>     </tr>
>
>     <tr>
>       <td>**Return**</td>
>       <td><pre>`{
>             "A": "B",
>             "C": {
>             "D": 5,
>             "F": 7
>             }
>             ]`</pre></td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_QUERY (json, path \[\<return>])
>
> Returns the JSON object at the given `path` in `json`; null, if the path doesn't exist
> or contains a primitive (non-object) value
>
> An optional `return` clause can be added to the end of the path to specify the return type
> of the object found, as well as the error handling for the object lookup.  The format of the
> clause is:
>
> ```
> [<wrapper> WRAPPER] [<empty_hand> ON EMPTY] [<error hand> ON ERROR]
> ```
>
> > [!NOTE]
> >
> > Return clause is only available in SQL or in the native API via
> > [/execute/sql](https://docs.kinetica.com/content/api/rest/execute_sql_rest.md).
>
> <table>
>   <thead>
>     <tr>
>       <th>Parameter</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`<wrapper>`</td>
>       <td>Whether the returned object(s) should be wrapped in an array before being returned Valid wrapping schemes include: <ul><li>`WITHOUT [ARRAY]` - no wrapper is applied *(default)*</li><li>`WITH [UNCONDITIONAL] [ARRAY]` - return the object(s) in an array</li><li>`WITH CONDITIONAL [ARRAY]` - if returning a single object, don't wrap it; if returning multiple objects, wrap them in an array</li></ul></td>
>     </tr>
>
>     <tr>
>       <td>`<empty hand>`</td>
>       <td>The scheme to use for handling empty returned objects Valid schemes include: <ul><li>`NULL` - return *null* *(default)*</li><li>`ERROR` - throw an error</li><li>`EMPTY ARRAY` - return an empty array</li><li>`EMPTY OBJECT` - return an empty object</li></ul></td>
>     </tr>
>
>     <tr>
>       <td>`<error hand>`</td>
>       <td>The scheme to use for handling errors in looking up the object Valid schemes include: <ul><li>`NULL` - return *null* *(default)*</li><li>`ERROR` - throw an error</li><li>`EMPTY ARRAY` - return an empty array</li><li>`EMPTY OBJECT` - return an empty object</li></ul></td>
>     </tr>
>   </tbody>
> </table>
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_QUERY('[1, 2]', '$')`</td>
>       <td>`[1,2]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('[1, 2]', '$.A')`</td>
>       <td>*null*</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('{"A": [2, 3]}', '$.A')`</td>
>       <td>`[2,3]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('{"A": {"B": 3, "D": 5}}', '$["A"]')`</td>
>       <td>`{"B":3,"D":5}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('{"A": {"B": 3, "D": 5}}', '$["A"]["D"]')`</td>
>       <td>*null*</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('{"A": {"B": 3, "D": [5, 6]}}', '$["A"]["D"]')`</td>
>       <td>`[5,6]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('{"A": []}', '$.B'  EMPTY ARRAY ON EMPTY)`</td>
>       <td>`[]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('{"A": 0}', '$.A'  EMPTY OBJECT ON ERROR)`</td>
>       <td>`{}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('{"A": 2, "C": 4}', '$.*')`</td>
>       <td>*null*</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_QUERY('{"A": 2, "C": 4}', '$.*' WITH WRAPPER)`</td>
>       <td>`[2,4]`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_REPLACE(json, path, repl)
>
> Returns the given `json` with the value at the JSON path `path` replaced with the
> replacement value `repl`
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_REPLACE('[1, 2]', '$', '[3, 4]')`</td>
>       <td>`[3,4]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_REPLACE('[1, 2]', '$.A', '"B"')`</td>
>       <td>`[1,2]`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_REPLACE('{"A": [2, 3]}', '$.A', '{"D": 5}')`</td>
>       <td>`{"A":{"D":5}}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_REPLACE('{"A": {"B": 3}}', '$["A"]', '"D"')`</td>
>       <td>`{"A":"D"}`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_REPLACE('{"A": {"B": [3, 4]}}', '$["A"]["B"]', 5)`</td>
>       <td>`{"A":{"B":5}}`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_TYPE(expr)
>
> Returns the JSON type of the given `expr`
>
> <table>
>   <thead>
>     <tr>
>       <th>Expression Type</th>
>       <th>JSON Type</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`BOOLEAN`</td>
>       <td>`BOOLEAN`</td>
>     </tr>
>
>     <tr>
>       <td><ul><li>`TINYINT`</li><li>`SMALLINT`</li><li>`INTEGER`</li><li>`BIGINT`</li><li>`UNSIGNED BIGINT`</li></ul></td>
>       <td>`LONG`</td>
>     </tr>
>
>     <tr>
>       <td><ul><li>`REAL`</li><li>`DOUBLE`</li></ul></td>
>       <td>`DOUBLE`</td>
>     </tr>
>
>     <tr>
>       <td><ul><li>`JSON`</li><li>`VARCHAR`</li></ul></td>
>       <td><ul><li>`BOOLEAN` - if `true` or `false`</li><li>`LONG` - if an integer value</li><li>`DOUBLE` - if a floating-point value</li><li>`STRING` - if a double-quoted literal</li><li>`OBJECT` - if a JSON map</li><li>`ARRAY` - if a JSON array</li></ul></td>
>     </tr>
>
>     <tr>
>       <td>`ARRAY` *(any)*</td>
>       <td>`ARRAY`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] JSON\_VALUE (json, path \[return])
>
> Returns the JSON value at the given `path` in `json`; null, if the path doesn't exist
> or contains an object (non-primitive) value
>
> An optional `return` clause can be added to the end of the path to specify the return type
> of the value found, as well as the error handling for the value lookup.  The format of the
> clause is:
>
> ```
> [RETURNING <type>] [<empty_hand> ON EMPTY] [<error hand> ON ERROR]
> ```
>
> > [!NOTE]
> >
> > Return clause is only available in SQL or in the native API via
> > [/execute/sql](https://docs.kinetica.com/content/api/rest/execute_sql_rest.md).
>
> <table>
>   <thead>
>     <tr>
>       <th>Parameter</th>
>       <th>Description</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`<type>`</td>
>       <td>The JSON type of the value to return; if the value is not already of that type, it will be cast to that type, if possible Valid types include: <ul><li>`BOOLEAN`</li><li>`LONG`</li><li>`DOUBLE`</li><li>`STRING`</li></ul></td>
>     </tr>
>
>     <tr>
>       <td>`<empty hand>`</td>
>       <td>The scheme to use for handling empty returned values Valid schemes include: <ul><li>`NULL` - return *null* *(default)*</li><li>`ERROR` - throw an error</li><li>`DEFAULT <expr>` - return the given expression `expr`</li></ul></td>
>     </tr>
>
>     <tr>
>       <td>`<error hand>`</td>
>       <td>The scheme to use for handling errors in looking up the value Valid schemes include: <ul><li>`NULL` - return *null* *(default)*</li><li>`ERROR` - throw an error</li><li>`DEFAULT <expr>` - return the given expression `expr`</li></ul></td>
>     </tr>
>   </tbody>
> </table>
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`JSON_VALUE('1', '$')`</td>
>       <td>`1`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_VALUE('[1, 2]', '$.A')`</td>
>       <td>*null*</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_VALUE('["A", "B"]', '$.1')`</td>
>       <td>`B`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_VALUE('{"A": [2, 3]}', '$["A"]["1"]')`</td>
>       <td>`3`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_VALUE('{"A": {"B": 3, "D": 5}}', '$["A"]["D"]')`</td>
>       <td>`5`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_VALUE('{"A": {"B": 3, "D": [5, 6]}}', '$.A.D.1')`</td>
>       <td>`6`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_VALUE('1', '$' RETURNING DOUBLE)`</td>
>       <td>`1.0`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_VALUE('{"A": []}', '$.B' DEFAULT '<null>' ON EMPTY)`</td>
>       <td>`<null>`</td>
>     </tr>
>
>     <tr>
>       <td>`JSON_VALUE('{"A": []}', '$.A' ERROR ON ERROR)`</td>
>       <td>*error returned*</td>
>     </tr>
>   </tbody>
> </table>

#### Aggregation Functions

The following functions can be used on [JSON](https://docs.kinetica.com/content/concepts/json.md)
columns within [aggregations](https://docs.kinetica.com/content/concepts/expressions.md#aggregate-expressions-label).

> [accordion] JSON\_ARRAYAGG(expr)
>
> Combines column values within a group into a single JSON array of those values.
>
> See [examples](https://docs.kinetica.com/content/concepts/json.md#json-func-agg-ex-agg).

> [accordion] JSON\_ARRAYAGG\_DISTINCT(expr)
>
> Combines column values within a group into a single JSON array of those values,
> removing any duplicates.
>
> See [examples](https://docs.kinetica.com/content/concepts/json.md#json-func-agg-ex-agg-dist).

> [accordion] JSON\_COLLECT\_SET(expr)
>
> Alias for `JSON_ARRAYAGG_DISTINCT`.

### Math Functions

#### Scalar Functions

> [accordion] ABS(expr)
>
> Calculates the absolute value of `expr`

> [accordion] ACOS(expr)
>
> Returns the inverse cosine (arccosine) of `expr` as a *double*

> [accordion] ACOSF(expr)
>
> Returns the inverse cosine (arccosine) of `expr` as a *float*

> [accordion] ACOSH(expr)
>
> Returns the inverse hyperbolic cosine of `expr` as a *double*

> [accordion] ACOSHF(expr)
>
> Returns the inverse hyperbolic cosine of `expr` as a *float*

> [accordion] ASIN(expr)
>
> Returns the inverse sine (arcsine) of `expr` as a *double*

> [accordion] ASINF(expr)
>
> Returns the inverse sine (arcsine) of `expr` as a *float*

> [accordion] ASINH(expr)
>
> Returns the inverse hyperbolic sine of `expr` as a *double*

> [accordion] ASINHF(expr)
>
> Returns the inverse hyperbolic sine of `expr` as a *float*

> [accordion] ATAN(expr)
>
> Returns the inverse tangent (arctangent) of `expr` as a *double*

> [accordion] ATANF(expr)
>
> Returns the inverse tangent (arctangent) of `expr` as a *float*

> [accordion] ATANH(expr)
>
> Returns the inverse hyperbolic tangent of `expr` as a *double*

> [accordion] ATANHF(expr)
>
> Returns the inverse hyperbolic tangent of `expr` as a *float*

> [accordion] ATAN2(x, y)
>
> Returns the inverse tangent (arctangent) using two arguments as a *double*

> [accordion] ATAN2F(x, y)
>
> Returns the inverse tangent (arctangent) using two arguments as a *float*

> [accordion] ATN2(x, y)
>
> Alias for `ATAN2`

> [accordion] ATN2F(x, y)
>
> Alias for `ATAN2F`

> [accordion] CBRT(expr)
>
> Returns the cube root of `expr` as a *double*

> [accordion] CBRTF(expr)
>
> Returns the cube root of `expr` as a *float*

> [accordion] CEIL(expr)
>
> Alias for `CEILING`

> [accordion] CEILING(expr)
>
> Rounds `expr` up to the next highest integer

> [accordion] COS(expr)
>
> Returns the cosine of `expr` as a *double*

> [accordion] COSF(expr)
>
> Returns the cosine of `expr` as a *float*

> [accordion] COSH(expr)
>
> Returns the hyperbolic cosine of `expr` as a *double*

> [accordion] COSHF(expr)
>
> Returns the hyperbolic cosine of `expr` as a *float*

> [accordion] COT(expr)
>
> Returns the cotangent of `expr` as a *double*

> [accordion] COTF(expr)
>
> Returns the cotangent of `expr` as a *float*

> [accordion] DEGREES(expr)
>
> Returns the conversion of `expr` (in radians) to degrees as a *double*

> [accordion] DEGREESF(expr)
>
> Returns the conversion of `expr` (in radians) to degrees as a *float*

> [accordion] DIVZ(a, b, c)
>
> Returns the quotient `a / b` unless `b == 0`, in which case it returns `c`

> [accordion] EXP(expr)
>
> Returns *e* to the power of `expr` as a *double*

> [accordion] EXPF(expr)
>
> Returns *e* to the power of `expr` as a *float*

> [accordion] FLOOR(expr)
>
> Rounds `expr` down to the next lowest integer

> [accordion] GREATER(expr\_a, expr\_b)
>
> Returns whichever of `expr_a` and `expr_b` has the larger value, based on typed
> comparison

> [accordion] HYPOT(x, y)
>
> Returns the hypotenuse of `x` and `y` as a *double*

> [accordion] HYPOTF(x, y)
>
> Returns the hypotenuse of `x` and `y` as a *float*

> [accordion] IFERROR(expr, val)
>
> Alias for `IF_ERROR(expr, val)`

> [accordion] IFINF(expr, val)
>
> Alias for `IF_INF(expr, val)`

> [accordion] IFINFINITY(expr, val)
>
> Alias for `IF_INF(expr, val)`

> [accordion] IFNAN(expr, val)
>
> Alias for `IF_NAN(expr, val)`

> [accordion] IF\_ERROR(expr, val)
>
> Evaluates the given *double* or *float* `expr`, and if it resolves to infinity or
> `NaN`, return `val`
>
> > [!TIP]
> >
> > Conceptually, this function is the same as
> > `IF_INF(IF_NAN(expr, val), val)`
>
> Example:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`IF_ERROR((double(10)/0), 1)`</td>
>       <td>`1.0`</td>
>     </tr>
>
>     <tr>
>       <td>`IF_ERROR(log(-1), 1)`</td>
>       <td>`1.0`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] IF\_INF(expr, val)
>
> Evaluates the given *double* or *float* `expr`, and if it resolves to infinity,
> return `val`
>
> Example:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`IF_INF((double(10)/0), 999)`</td>
>       <td>`999.0`</td>
>     </tr>
>
>     <tr>
>       <td>`IF_INF(log(-1), 999)`</td>
>       <td>`NaN`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] IF\_INFINITY(expr, val)
>
> Alias for `IF_INF(expr, val)`

> [accordion] IF\_NAN(expr, val)
>
> Evaluates the given *double* or *float* `expr`, and if it resolves to `NaN`,
> return `val`
>
> Example:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`IF_NAN((double(10)/0), -1)`</td>
>       <td>`Infinity`</td>
>     </tr>
>
>     <tr>
>       <td>`IF_NAN(log(-1), -1)`</td>
>       <td>`-1.0`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] ISINFINITY(expr)
>
> Returns `1` (true) if `expr` is infinity by IEEE standard; otherwise, returns
> `0` (false)

> [accordion] IS\_INFINITY(expr)
>
> Alias for `ISINFINITY`

> [accordion] ISNAN(expr)
>
> Returns `1` (true) if `expr` is not a number by IEEE standard; otherwise, returns
> `0` (false)

> [accordion] IS\_NAN(expr)
>
> Alias for `ISNAN`

> [accordion] ISNUMERIC(expr)
>
> Returns `1` (true) if `expr` is a number by IEEE standard; otherwise, returns
> `0` (false)

> [accordion] IS\_NUMERIC(expr)
>
> Alias for `ISNUMERIC`

> [accordion] LDEXP(x, exp)
>
> Returns the value of `x` \* 2<sup>exp</sup> as a *double*

> [accordion] LDEXPF(x, exp)
>
> Returns the value of `x` \* 2<sup>exp</sup> as a *float*

> [accordion] LESSER(expr\_a, expr\_b)
>
> Returns whichever of `expr_a` and `expr_b` has the smaller value, based on typed
> comparison

> [accordion] LN(expr)
>
> Returns the natural logarithm of `expr` as a *double*

> [accordion] LNF(expr)
>
> Returns the natural logarithm of `expr` as a *float*

> [accordion] LOG(expr)
>
> Alias for `LN`

> [accordion] LOG10(expr)
>
> Returns the *base-10* logarithm of `expr` as a *double*

> [accordion] LOG10F(expr)
>
> Returns the *base-10* logarithm of `expr` as a *float*

> [accordion] LOG1P(expr)
>
> Returns the natural logarithm of one plus `expr` as a *double*

> [accordion] LOG1PF(expr)
>
> Returns the natural logarithm of one plus `expr` as a *float*

> [accordion] LOG2(expr)
>
> Returns the binary (*base-2*) logarithm of `expr` as a *double*

> [accordion] LOG2F(expr)
>
> Returns the binary (*base-2*) logarithm of `expr` as a *float*

> [accordion] LOGF(expr)
>
> Alias for `LNF`

> [accordion] MAX\_CONSECUTIVE\_BITS(expr)
>
> Calculates the length of the longest series of consecutive `1` bits in the integer
> `expr`

> [accordion] MOD(dividend, divisor)
>
> Calculates the remainder after integer division of `dividend` by `divisor`

> [accordion] NEXT\_AFTER(expr\[, target])
>
> Returns the next representable floating-point value adjacent to
> `expr` in the direction of `target`, incrementing `expr`
> if `target` is greater, decrementing if lesser.  The default
> value of `target` is `MAX_DOUBLE` (always increments when
> omitted).  The return type matches the input (*float* or *double*).

> [accordion] NEXT\_BEFORE(expr)
>
> Returns the next representable floating-point value less than
> `expr`.  The return type matches the input (*float* or *double*).

> [accordion] PI()
>
> Returns the value of *pi*

> [accordion] POW(base, exponent)
>
> Alias for `POWER`

> [accordion] POWF(base, exponent)
>
> Alias for `POWERF`

> [accordion] POWER(base, exponent)
>
> Returns `base` raised to the power of `exponent` as a *double*

> [accordion] POWERF(base, exponent)
>
> Returns `base` raised to the power of `exponent` as a *float*

> [accordion] RADIANS(expr)
>
> Returns the conversion of `expr` (in degrees) to radians as a *double*

> [accordion] RADIANSF(expr)
>
> Returns the conversion of `expr` (in degrees) to radians as a *float*

> [accordion] RAND(\[seed])
>
> Returns a random floating-point value, with an optional `seed`

> [accordion] REGR\_VALX(y, x)
>
> Returns NULL if `y` is NULL; otherwise, returns `x`

> [accordion] REGR\_VALY(y, x)
>
> Returns NULL if `x` is NULL; otherwise, returns `y`

> [accordion] ROUND(expr\[, scale])
>
> Rounds `expr` to the nearest decimal number with `scale`
> decimal places when `scale` is a positive number; rounds to
> the nearest number such that the result has `-(scale)` zeros
> to the left of the decimal point when `scale` is negative; use
> `scale` of `0` to round to the nearest integer.
>
> The default value of `scale` is `0`.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`ROUND(12345.678)`</td>
>       <td>`12346`</td>
>     </tr>
>
>     <tr>
>       <td>`ROUND(12345.678, 2)`</td>
>       <td>`12345.68`</td>
>     </tr>
>
>     <tr>
>       <td>`ROUND(12345.678, 0)`</td>
>       <td>`12346`</td>
>     </tr>
>
>     <tr>
>       <td>`ROUND(12345.678, -2)`</td>
>       <td>`12300`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] SAFE\_DIVIDE(a, b)
>
> Returns the quotient `a / b` unless `b == 0`, in which case it returns `NULL`

> [accordion] SIGN(expr)
>
> Determines whether a number is positive, negative, or zero;
> returns one of the following three values:
>
> <table>
>   <thead>
>     <tr>
>       <th>Expression Value</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>*positive*</td>
>       <td>`1`</td>
>     </tr>
>
>     <tr>
>       <td>*zero*</td>
>       <td>`0`</td>
>     </tr>
>
>     <tr>
>       <td>*negative*</td>
>       <td>`-1`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] SIN(expr)
>
> Returns the sine of `expr` as a *double*

> [accordion] SINF(expr)
>
> Returns the sine of `expr` as a *float*

> [accordion] SINH(expr)
>
> Returns the hyperbolic sine of `expr` as a *double*

> [accordion] SINHF(expr)
>
> Returns the hyperbolic sine of `expr` as a *float*

> [accordion] SQRT(expr)
>
> Returns the square root of `expr` as a *double*

> [accordion] SQRTF(expr)
>
> Returns the square root of `expr` as a *float*

> [accordion] TAN(expr)
>
> Returns the tangent of `expr` as a *double*

> [accordion] TANF(expr)
>
> Returns the tangent of `expr` as a *float*

> [accordion] TANH(expr)
>
> Returns the hyperbolic tangent of `expr` as a *double*

> [accordion] TANHF(expr)
>
> Returns the hyperbolic tangent of `expr` as a *float*

> [accordion] TRUNCATE(expr\[, scale])
>
> Rounds `expr` down to the nearest decimal number with
> `scale` decimal places when `scale` is a positive number;
> rounds down to the nearest number such that the result has
> `-(scale)` zeros to the left of the decimal point when
> `scale` is negative; use `scale` of `0` to round down to
> the nearest integer.
>
> The default value of `scale` is `0`.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`TRUNCATE(12345.678)`</td>
>       <td>`12345`</td>
>     </tr>
>
>     <tr>
>       <td>`TRUNCATE(12345.678, 2)`</td>
>       <td>`12345.67`</td>
>     </tr>
>
>     <tr>
>       <td>`TRUNCATE(12345.678, 0)`</td>
>       <td>`12345`</td>
>     </tr>
>
>     <tr>
>       <td>`TRUNCATE(12345.678, -2)`</td>
>       <td>`12300`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] WIDTH\_BUCKET(expr, min, max, count)
>
> Defines a set of `count` equal intervals (buckets) within the range of `min` &
> `max`, and puts the value of `expr` into one of those buckets, where the value is
> greater than or equal to the minimum value of the bucket and less than the maximum
> value of the bucket.  Returns the 1-based number of the bucket into which the value
> of `expr` fell.  For values smaller than `min`, `0` is returned; for values
> greater than or equal to `max`, `count + 1` is returned.  Examples:
>
> In the following examples, a set of *5* equal buckets are defined between *0* and
> *10* (*0-2*, *2-4*, *4-6*, *6-8*, & *8-10*), and various values are bucketed using
> that set.
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`WIDTH_BUCKET(-1, 0, 10, 5)`</td>
>       <td>`0`</td>
>     </tr>
>
>     <tr>
>       <td>`WIDTH_BUCKET(0, 0, 10, 5)`</td>
>       <td>`1`</td>
>     </tr>
>
>     <tr>
>       <td>`WIDTH_BUCKET(5, 0, 10, 5)`</td>
>       <td>`3`</td>
>     </tr>
>
>     <tr>
>       <td>`WIDTH_BUCKET(10, 0, 10, 5)`</td>
>       <td>`6`</td>
>     </tr>
>
>     <tr>
>       <td>`WIDTH_BUCKET(11, 0, 10, 5)`</td>
>       <td>`6`</td>
>     </tr>
>   </tbody>
> </table>

#### Aggregate Functions

The following functions can be used on numeric
columns within [aggregations](https://docs.kinetica.com/content/concepts/expressions.md#aggregate-expressions-label).

> [accordion] APPROX\_COUNT\_DISTINCT(expr)
>
> The approximate number of distinct values of `expr`; this is faster to calculate than `COUNT_DISTINCT` but is only an approximation

> [accordion] APPROX\_MEDIAN(expr)
>
> The approximate median of `expr`; the result should be within about *2%* of the true median value. This is equivalent to issuing
> `APPROX_PERCENTILE(expr, 50)`.

> [accordion] APPROX\_PERCENTILE(expr, p)
>
> The approximate *pth* percentile of `expr`; `p` should be a value between *0.0* and *100.0*. `APPROX_PERCENTILE(expr, 50)` will return
> the approximate median of `expr`.

> [accordion] AVG(expr)
>
> Average of the values of `expr`

> [accordion] CORR(expr1, expr2)
>
> Correlation coefficient of the values of `expr1` and `expr2`

> [accordion] CORRELATION(expr1, expr2)
>
> Alias for `CORR`

> [accordion] CORRCOEF(expr1, expr2)
>
> Alias for `CORR`

> [accordion] COUNT(expr)
>
> Count of non-null values of `expr`; use `*` to count all values within an aggregation group or over an entire table

> [accordion] COUNT\_DISTINCT(expr)
>
> Count of the distinct values of `expr`

> [accordion] COV(expr1, expr2)
>
> Alias for `COVAR_POP`

> [accordion] COVAR(expr1, expr2)
>
> Alias for `COVAR_POP`

> [accordion] COVARIANCE(expr1, expr2)
>
> Alias for `COVAR_POP`

> [accordion] COVAR\_POP(expr1, expr2)
>
> Population covariance of the values of `expr1` and `expr2`

> [accordion] COVAR\_SAMP(expr1, expr2)
>
> Sample covariance of the values of `expr1` and `expr2`

> [accordion] KURT(expr)
>
> Alias for `KURTOSIS_POP`

> [accordion] KURTOSIS(expr)
>
> Alias for `KURTOSIS_POP`

> [accordion] KURTOSIS\_POP(expr)
>
> Population kurtosis of the values of `expr`

> [accordion] KURTOSIS\_SAMP(expr)
>
> Sample kurtosis of the values of `expr`

> [accordion] KURT\_POP(expr)
>
> Alias for `KURTOSIS_POP`

> [accordion] KURT\_SAMP(expr)
>
> Alias for `KURTOSIS_SAMP`

> [accordion] MAX(expr)
>
> Maximum of the values of `expr`

> [accordion] MEAN(expr)
>
> Alias for `AVG`

> [accordion] MIN(expr)
>
> Minimum of the values of `expr`

> [accordion] PRODUCT(expr)
>
> Product of the values of `expr`

> [accordion] REGR\_AVGX(y, x)
>
> Average of the independent variable (`SUM(x)/N`) of the line determined by computing a least-squares-fit linear regression over the given (X, Y)
> pairs

> [accordion] REGR\_AVGY(y, x)
>
> Average of the dependent variable (`SUM(y)/N`) of the line determined by computing a least-squares-fit linear regression over the given (X, Y)
> pairs

> [accordion] REGR\_COUNT(y, x)
>
> Number of input rows used in computing a linear regression, where both expressions are non-null

> [accordion] REGR\_INTERCEPT(y, x)
>
> Y-intercept of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

> [accordion] REGR\_R2(y, x)
>
> Square of the correlation coefficient, marking how well the least-squares-fit linear regression fit the data set

> [accordion] REGR\_SLOPE(y, x)
>
> Slope of the line determined by computing a least-squares-fit linear regression over the given (X, Y) pairs

> [accordion] REGR\_SXX(y, x)
>
> "Sum of squares" of the independent variable (`SUM(x^2) - SUM(x)^2/N`) of the line determined by computing a least-squares-fit linear regression
> over the given (X, Y) pairs

> [accordion] REGR\_SXY(y, x)
>
> "Sum of Products" of independent variable times dependent variable (`SUM(x * y) - SUM(x) * SUM(y)/N`) of the line determined by computing a
> least-squares-fit linear regression over the given (X, Y) pairs

> [accordion] REGR\_SYY(y, x)
>
> "Sum of squares" of the dependent variable (`SUM(y^2) - SUM(y)^2/N`) of the line determined by computing a least-squares-fit linear regression
> over the given (X, Y) pairs

> [accordion] SKEW(expr)
>
> Alias for `SKEWNESS_POP`

> [accordion] SKEWNESS(expr)
>
> Alias for `SKEWNESS_POP`

> [accordion] SKEWNESS\_POP(expr)
>
> Population skew of the values of `expr`

> [accordion] SKEWNESS\_SAMP(expr)
>
> Sample skew of the values of `expr`

> [accordion] SKEW\_POP(expr)
>
> Alias for `SKEWNESS_POP`

> [accordion] SKEW\_SAMP(expr)
>
> Alias for `SKEWNESS_SAMP`

> [accordion] STDDEV(expr)
>
> Population standard deviation over values of `expr` (i.e. the denominator is *N*)

> [accordion] STDDEV\_POP(expr)
>
> Population standard deviation over values of `expr` (i.e. the denominator is *N*)

> [accordion] STDDEV\_SAMP(expr)
>
> Sample standard deviation over values of `expr` (i.e. the denominator is *N-1*)

> [accordion] SUM(expr)
>
> Sum of the values of `expr`

> [accordion] VAR(expr)
>
> Population variance over values of `expr` (i.e. the denominator is *N*)

> [accordion] VAR\_POP(expr)
>
> Population variance over values of `expr` (i.e. the denominator is *N*)

> [accordion] VAR\_SAMP(expr)
>
> Sample variance over values of `expr` (i.e. the denominator is *N-1*)

> [accordion] VARIANCE(expr)
>
> Alias for `VAR`

> [accordion] VARIANCE\_POP(expr)
>
> Alias for `VAR_POP`

> [accordion] VARIANCE\_SAMP(expr)
>
> Alias for `VAR_SAMP`

### Null Functions

> [!NOTE]
>
> Be mindful that no error is thrown when *Kinetica* tries to
> convert different data [type](https://docs.kinetica.com/content/concepts/types.md#types) in the *Null*
> functions below, so if the output is unexpected, it may be that
> the *types* used aren't of the same *type*.

> [accordion] IS\_DISTINCT\_FROM(expr\_a, expr\_b)
>
> Returns *false* if `expr_a` equals `expr_b` or both are *null*; otherwise, returns
> *true*.  Unlike `<>`, returns *true* (not *null*) when exactly one expression is *null*.
> Both expressions should be of the same or convertible data type.

> [accordion] IS\_NOT\_DISTINCT\_FROM(expr\_a, expr\_b)
>
> Returns *true* if `expr_a` equals `expr_b` or both are *null*; otherwise, returns
> *false*.  Unlike `=`, returns *false* (not *null*) when exactly one expression is *null*.
> Both expressions should be of the same or convertible data type.

> [accordion] IS\_NULL(expr)
>
> Returns *true* if `expr` is *null*; otherwise, returns *false*.

> [accordion] ISNULL(expr)
>
> Alias for `IS_NULL(expr)`

> [accordion] NULLIF(expr\_a, expr\_b)
>
> Returns *null* if `expr_a` equals `expr_b`; otherwise, returns the
> value of `expr_a`. Both expressions should be of the same convertible
> data type

> [accordion] NVL(expr\_a, expr\_b)
>
> Returns `expr_a` if it is not *null*; otherwise, returns `expr_b`.
> Both expressions should be of the same convertible data type; see
> [Short-Circuiting](https://docs.kinetica.com/content/concepts/expressions.md#short-circuiting) for error-checking details

> [accordion] NVL2(expr, value\_if\_not\_null, value\_if\_null)
>
> Evaluates `expr`: if `expr` does not return a *null*,
> `value_if_not_null` is returned. If `expr` does return a *null*,
> `value_if_null` is returned. Both `value_if_not_null` and
> `value_if_null` should be of the same data type as `expr` or
> implicitly convertible; see [Short-Circuiting](https://docs.kinetica.com/content/concepts/expressions.md#short-circuiting) for error-checking details

> [accordion] REMOVE\_NULLABLE(expr)
>
> Alias for `ZEROIFNULL`

> [accordion] ZEROIFNULL(expr)
>
> Replaces *null* values with appropriate values based on the column type (e.g., `0` if
> numeric column, an empty string if string column, etc.). Also removes the `nullable`
> [column property](https://docs.kinetica.com/content/concepts/types.md) if used to calculate a derived column.

### Record Distribution Functions

Record distribution functions provide a means to locate any database record
within the memory processing hierarchy; and through aggregating the results,
determine the distribution of records across the cluster.

> [accordion] KI\_CHUNK()
>
> Returns the index of the chunk within the rank/TOM containing this record.
> This value may change as data is added or deleted from a table.

> [accordion] KI\_CHUNK\_ID()
>
> Returns the ID of the chunk within the rank/TOM containing this record.
> This value should remain the same even after system restarts.

> [accordion] KI\_CHUNK\_MAX(col)
>
> Returns the maximum value for the specified column in its chunk.
> If the data has changed, this value may be higher than any actual values.

> [accordion] KI\_CHUNK\_MIN(col)
>
> Returns the minimum value for the specified column in its chunk.
> If the data has changed, this value may be lower than any actual values.

> [accordion] KI\_CHUNK\_OFFSET()
>
> Returns the index of the record within the chunk.

> [accordion] KI\_PARTITION()
>
> Returns the index of the partition within the rank/TOM containing this record, for
> [partitioned](https://docs.kinetica.com/content/concepts/tables.md#partitioning) tables.

> [accordion] KI\_RANK()
>
> Returns the index of the rank containing this record.

> [accordion] KI\_TOM()
>
> Returns the index of the TOM within the rank containing this record.

### String Functions

There are two different types of string functions:

* [Scalar Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-string-scalar)
* [Aggregate Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-string-agg)

> [!NOTE]
>
> String columns are stored as byte arrays, but allow multi-byte
> characters, as they are UTF-8 encoded.  Some functions may behave in
> unexpected ways when given multi-byte input.

#### Scalar Functions

> [accordion] ASCII(expr)
>
> Returns the ASCII code for the first byte in `expr`

> [accordion] BIN(expr\[, minimum\_digits])
>
> Convert the value represented by `expr` into a binary string
> representation.  Use optional `minimum_digits` to add leading 0s
> when needed; defaults to 1.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`BIN(42)`</td>
>       <td>`'101010'`</td>
>     </tr>
>
>     <tr>
>       <td>`BIN(42, 8)`</td>
>       <td>`'00101010'`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] CHAR(expr)
>
> The character represented by the standard ASCII code `expr` in the
> range \[ `0` - `127` ]

> [accordion] CONCAT(expr\_a, expr\_b)
>
> Performs a string concatenation of `expr_a` & `expr_b`; use nested
> `CONCAT` calls to concatenate more than two strings
>
> > [!NOTE]
> >
> > The resulting field size of any `CONCAT` will be a string
> > field big enough to hold the concatenated fields, e.g.,
> > concatenating a *char32* column and a *char64* column will
> > result in a *char128* column.  Concatenations longer than
> > 256 characters will use an unrestricted-width string type.

> [accordion] CONCAT\_TRUNCATE(expr\_a, expr\_b)
>
> Returns the concatenation of `expr_a` and `expr_b`, truncated at
> the maximum size of the larger of `expr_a` and `expr_b`.
> For data columns, the size is explicit; for string constants, the size
> will be the smallest *charN* type that can hold the constant string.
>
> > [!NOTE]
> >
> > `CONCAT_TRUNCATE` will not work if any parameter is an
> > unrestricted-width string.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`CONCAT_TRUNCATE('ABC123','!')`</td>
>       <td>`ABC123!`</td>
>     </tr>
>
>     <tr>
>       <td>`CONCAT_TRUNCATE('AB','CDE')`</td>
>       <td>`ABCD` *(char4 is* *the minimum size* *required to hold the* `CDE` *value, so* *the result is truncated* *at 4 characters)*</td>
>     </tr>
>
>     <tr>
>       <td>`CONCAT_TRUNCATE('ABCD1234','DEFG')`</td>
>       <td>`ABCD1234` *(an 8-character string* *is the minimum size* *required to hold the* `ABCD1234` *value, so* *no characters can be* *appended)*</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] CONTAINS(match, expr)
>
> Returns `1` if `expr` contains `match` by
> string-literal comparison; otherwise, returns `0`

> [accordion] CONV(expr, from\_base, to\_base)
>
> Convert the value represented by the `expr` string from one
> numeric base to another.  Base parameters may be \[`2` - `36`].
> Binary, octal and hexadecimal strings may have an optional prefix.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`CONV('42', 10, 16)`</td>
>       <td>`'2A'`</td>
>     </tr>
>
>     <tr>
>       <td>`CONV('2a', 16, 10)`</td>
>       <td>`'42'`</td>
>     </tr>
>
>     <tr>
>       <td>`CONV('11', 2, 10)`</td>
>       <td>`'3'`</td>
>     </tr>
>
>     <tr>
>       <td>`CONV('0o52', 8, 2)`</td>
>       <td>`'101010'`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] DEC2HEX(expr\[, minimum\_digits])
>
> Alias for `HEX`

> [accordion] DIFFERENCE(expr\_a, expr\_b)
>
> Returns a value between `0` and `4` that represents the difference
> between the sounds of `expr_a` and `expr_b` based on the
> `SOUNDEX()` value of the strings--a value of `4` is the best
> possible sound match

> [accordion] EDIT\_DISTANCE(expr\_a, expr\_b)
>
> Returns the Levenshtein edit distance between `expr_a` and
> `expr_b`; the lower the value, the more similar the two strings are

> [accordion] ENDS\_WITH(match, expr)
>
> Returns `1` if `expr` ends with `match` by
> string-literal comparison; otherwise, returns `0`

> [accordion] FROM\_HEX(expr)
>
> Alias for `UNHEX`

> [accordion] HEX(expr\[, minimum\_digits])
>
> Convert the value represented by `expr` into a hexadecimal string
> representation.  Use optional `minimum_digits` to add leading 0s
> when needed; defaults to 1.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`HEX(42)`</td>
>       <td>`'2A'`</td>
>     </tr>
>
>     <tr>
>       <td>`HEX(42, 8)`</td>
>       <td>`'0000002A'`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] HEX2DEC(expr)
>
> Alias for `UNHEX`

> [accordion] ILIKE(expr, match\[, esc\_char])
>
> Returns whether `expr` matches the given `match`.  The
> match is a string literal one with the following exceptions:
>
> * `%` matches any string of 0 or more characters
> * `_` matches any single character
> * `[character_set]` matches any single character listed in the set.
>   The `character_set` may contain ranges using a dash (`-`).  A
>   A `character_set` starting with `^` will match any character not
>   in the specified set.
>
> By default, the escape character used to match special characters,
> such as `%`, in the `expr` literally is `\`.  The `esc_char`,
> if given, will override this default escape character.
>
> `ILIKE` is case-insensitive.  For a case-sensitive match, see
> `LIKE`.
>
> > [!NOTE]
> >
> > The match expression has to match the reference expression
> > completely--it will not return *true* for partial matches.
> > Add `%` before and/or after the match for partial matches.
>
> Examples of successful matches:
>
> | Function Call |
> | - |
> | `ILIKE('Brook', 'BROOK')` |
> | `ILIKE('Brooke', 'BROOK_')` |
> | `ILIKE('Brooklyn', 'BROOK%')` |
> | `ILIKE('50_50', '50\\_50')` |
> | `ILIKE('100%', '100\\%')` |
> | `ILIKE('50\\50', '50\\\\50')` |
> | `ILIKE('abqd', 'AB[A-Z]D')` |
> | `ILIKE('abqd', 'AB[^0-9]D')` |
> | `ILIKE('ab-d', 'AB[123~-]D', '~')` |
> | `ILIKE('a_c', 'A~_C', '~')` |
> | `ILIKE('100%', '100~%', '~')` |

> [accordion] INITCAP(expr)
>
> Returns `expr` with the first letter of each word in uppercase

> [accordion] IPV4\_PART(expr, part\_num)
>
> Returns the octet of the IP address given in `expr` at the position
> specified by `part_num`.   Valid `part_num` values are constants
> from `1` to `4`.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`IPV4_PART('12.34.56.78', 1)`</td>
>       <td>`12`</td>
>     </tr>
>
>     <tr>
>       <td>`IPV4_PART('12.34.56.78', 4)`</td>
>       <td>`78`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] IS\_IPV4(expr)
>
> Returns `1` if `expr` is an IPV4 address; returns `0` otherwise

> [accordion] ISIPV4(expr)
>
> Alias for `IS_IPV4`

> [accordion] LCASE(expr)
>
> Converts `expr` to lowercase

> [accordion] LEFT(expr, num\_bytes)
>
> Returns the leftmost `num_bytes` bytes from `expr`

> [accordion] LEN(expr)
>
> Alias for `LENGTH`

> [accordion] LENGTH(expr)
>
> Returns the number of characters in `expr`

> [accordion] LIKE(expr, match\[, esc\_char])
>
> Returns whether `expr` matches the given `match`.  The
> match is a string literal one with the following exceptions:
>
> * `%` matches any string of 0 or more characters
> * `_` matches any single character
> * `[character_set]` matches any single character listed in the set.
>   The `character_set` may contain ranges using a dash (`-`).  A
>   A `character_set` starting with `^` will match any character not
>   in the specified set.
>
> By default, the escape character used to match special characters,
> such as `%`, in the `expr` literally is `\`.  The `esc_char`,
> if given, will override this default escape character.
>
> `LIKE` is case-sensitive.  For a case-insensitive match, see
> `ILIKE`.
>
> > [!NOTE]
> >
> > The match expression has to match the reference expression
> > completely--it will not return *true* for partial matches.
> > Add `%` before and/or after the match for partial matches.
>
> Examples of successful matches:
>
> | Function Call |
> | - |
> | `LIKE('Brook', 'Brook')` |
> | `LIKE('Brooke', 'Brook_')` |
> | `LIKE('Brooklyn', 'Brook%')` |
> | `LIKE('50_50', '50\\_50')` |
> | `LIKE('100%', '100\\%')` |
> | `LIKE('50\\50', '50\\\\50')` |
> | `LIKE('abqd', 'ab[a-z]d')` |
> | `LIKE('abqd', 'ab[^0-9]d')` |
> | `LIKE('ab-d', 'ab[123~-]d', '~')` |
> | `LIKE('a_c', 'a~_c', '~')` |
> | `LIKE('100%', '100~%', '~')` |

> [accordion] LOCATE(match, expr\[, start\_pos])
>
> Returns the starting position of the first match of `match` in
> `expr`, starting from position 1 or `start_pos` (if
> specified).  If `match` can't be found or `start_pos` is
> outside the range of letters in `expr`, a `0` is returned.

> [accordion] LOWER(expr)
>
> Alias for `LCASE`

> [accordion] LPAD(expr, length\[, pad])
>
> Left pads the given `expr` string with the `pad` string
> to the given `length` of bytes. If `expr` is longer than
> `length`, the return value is shortened to `length` bytes. If
> `length` is larger than 256, it will be truncated to 256 bytes.  The
> default padding character is a space.
>
> > [!WARNING]
> >
> > The use of multi-byte characters in this function may
> > have unexpected results.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`LPAD('test', 9, 'pad')`</td>
>       <td>`padpatest`</td>
>     </tr>
>
>     <tr>
>       <td>`LPAD('test', 3, 'pad')`</td>
>       <td>`tes`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] LTRIM(expr)
>
> Removes whitespace from the left side of `expr`

> [accordion] OCT(expr\[, minimum\_digits])
>
> Convert the value represented by `expr` into an octal (base 8)
> string representation.  Use optional `minimum_digits` to add leading
> 0s when needed; defaults to 1.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`OCT(42)`</td>
>       <td>`'52'`</td>
>     </tr>
>
>     <tr>
>       <td>`OCT(42, 8)`</td>
>       <td>`'00000052'`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] PG\_SIZE\_PRETTY(expr)
>
> Alias for `SIZE_PRETTY`

> [accordion] POSITION(match, expr\[, start\_pos])
>
> Alias for `LOCATE`

> [accordion] REGEXP\_COUNT (expr, regex\[, position \[, mode]])
>
> Returns a count of the number of times the `regex` pattern is
> matched in `expr`.  Matches do not overlap, so the start of a future
> match must start after the end of the previous match.
>
> The `regex` parameter is the regular expression to try to match.
> It must be a string-literal with 256 characters or fewer.  Generally,
> POSIX-compliant regular expressions are supported for `regex`.
> The escape character used to match wildcards in the `expr` literally
> is `\`.  See `REGEXP_LIKE` for more regular expression examples.
>
> The optional `position` parameter specifies where to start searching
> in `expr` for the first match.  The first character in the string
> has a `position` of `1` (the default).
>
> The optional `mode` parameter is a string which can be empty
> (the default) for the default behavior.  See `REGEXP_LIKE` for the
> list of supported mode flags.
>
> Examples of `REGEXP_COUNT`:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`REGEXP_COUNT('abababab', 'abab')`</td>
>       <td>2</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_COUNT('abababab', 'abab', 2)`</td>
>       <td>1</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_COUNT('don''t', 'DON''T', 1, 'i')`</td>
>       <td>1</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] REGEXP\_INSTR (expr, regex \[, position \[, occurrence \[, begin\_end \[, mode \[,group]]]]])
>
> Returns the starting position (1-based) in `expr` where a `regex`
> match is found.  If no match is found, `0` is returned.
>
> The `regex` parameter is the regular expression to try to match.
> It must be a string-literal with 256 characters or fewer.  Generally,
> POSIX-compliant regular expressions are supported for `regex`.
> The escape character used to match wildcards in the `expr` literally
> is `\`.  See `REGEXP_LIKE` for more regular expression examples.
>
> The optional `position` parameter specifies where to start searching
> in `expr` for the first match.  The first character in the string
> has a `position` of `1` (the default).
>
> The optional `occurrence` parameter specifies which occurrence of
> the `regex` match is desired.  For example, `2` would return the
> second occurrence of `regex` in `expr`.  Matches do not overlap,
> so the start of a future match must start after the end of the
> previous match.
>
> The optional `begin_end` parameter specifies if the beginning or
> ending position is desired.  Use `0` (the default) for the beginning
> of the match and use `1` for the position after the end of the
> match.
>
> The optional `mode` parameter is a string which can be empty
> (the default) for the default behavior.  See `REGEXP_LIKE` for the
> list of supported mode flags.
>
> The optional `group` parameter specifies which regular expression
> group's (i.e., parentheses inside `regex`) beginning/ending position
> to return.  The default of `0` uses the entire matched expression,
> while a `group` of `1`  through `9` corresponds to the 1st group
> up through the 9th group of the match.
>
> Examples of `REGEXP_INSTR`:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`REGEXP_INSTR('abcdefg', 'bc')`</td>
>       <td>2</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_INSTR('abcdefg', 'ab', 2)`</td>
>       <td>0</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_INSTR('abcabc', 'a', 1, 2)`</td>
>       <td>4</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_INSTR('abcabc', 'abc', 1, 1, 1)`</td>
>       <td>4</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_INSTR('abcabc', 'B C', 1, 1, 0, 'ix')`</td>
>       <td>2</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_INSTR('abcdefg', '(C(.(.)))', 1, 1, 0, 'i', 3)`</td>
>       <td>5</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] REGEXP\_LIKE(expr, regex\[, mode])
>
> Returns whether `expr` matches the given `regex`.  Generally,
> POSIX-compliant regular expressions are supported.
>
> The optional `mode` parameter is a string which can be empty
> (the default) for the default behavior.  It can contain the following
> letters for the associated optional modified behaviors:
>
> <table>
>   <thead>
>     <tr>
>       <th>Letter</th>
>       <th>Meaning</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`i`</td>
>       <td>Case-insensitive matches</td>
>     </tr>
>
>     <tr>
>       <td>`m`</td>
>       <td>Treat input as multiple lines so `^` and `$` match around newlines and not just the beginning and ending of the string</td>
>     </tr>
>
>     <tr>
>       <td>`n`</td>
>       <td>Allows `.` to also match a newline character</td>
>     </tr>
>
>     <tr>
>       <td>`x`</td>
>       <td>Ignore any whitespace (e.g., spaces) in `regex`</td>
>     </tr>
>   </tbody>
> </table>
>
> The escape character used to match wildcards in the `expr` literally
> is `\`.
>
> > [!NOTE]
> >
> > The `regex` can match the `expr` partially.  To perform
> > full matches, `^` and `$` can be used to match the
> > start and end of `expr`, respectively.
>
> Examples of successful matches:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Match Type</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`REGEXP_LIKE('partial', 'part')`</td>
>       <td>Partial</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('Case', 'cAsE', 'i')`</td>
>       <td>Case-insensitive</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('dot', 'd.t')`</td>
>       <td>Any character</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('range', 'ra[a-z]ge')`</td>
>       <td>Character range</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('zeroorone', 'z?zer(oor)?one')`</td>
>       <td>0 or 1 token</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('zeroormore', 'z*zer([om]or)*e')`</td>
>       <td>0 or more tokens</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('oneormore', 'o+n([em]or)+e')`</td>
>       <td>1 or more tokens</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('A to Z', '^A.*Z$')`</td>
>       <td>Begin/End</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('41ph4Num', '^[[:alnum:]]+$')`</td>
>       <td>Character class</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_LIKE('Escape?', 'Escape?')`</td>
>       <td>Escape wildcard</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] REGEXP\_MATCH(expr, regex\[, options])
>
> Alias for `REGEXP_LIKE`

> [accordion] REGEXP\_REPLACE (expr, regex \[, replace \[, position \[, occurrence \[, mode]]]])
>
> Returns the `expr` string after replacing `regex` matches with the
> `replace` string parameter.
>
> The `regex` parameter is the regular expression to try to match.
> It must be a string-literal with 256 characters or fewer.  Generally,
> POSIX-compliant regular expressions are supported for `regex`.
> The escape character used to match wildcards in the `expr` literally
> is `\`.  See `REGEXP_LIKE` for more regular expression examples.
>
> The `replace` parameter is the optional text with which to replace
> each match of `regex` in `expr`.  The default is an empty string,
> which will simply remove the specified occurrences of `regex` in
> `expr`.  A `replace` of `\0` will insert the entire matched
> expression, while a `replace` of `\1` through `\9` will use the
> corresponding matched grouping (parentheses inside `regex`) as the
> replacement text.
>
> The optional `position` parameter specifies where to start searching
> in `expr` for the first match.  The first character in the string
> has a `position` of `1` (the default).
>
> The optional `occurrence` parameter specifies which occurrence of
> the `regex` match to replace.  For example, `2` would only replace
> the second occurrence of `regex` in `expr`.  Matches do not
> overlap, so the start of a future match must start after the end of
> the previous match.  Use `0` (the default) to replace all
> occurrences.
>
> The optional `mode` parameter is a string which can be empty
> (the default) for the default behavior.  See `REGEXP_LIKE` for the
> list of supported mode flags.
>
> Examples of `REGEXP_REPLACE`:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`REGEXP_REPLACE('abc', 'b')`</td>
>       <td>ac</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_REPLACE('abc', 'b.', 'x')`</td>
>       <td>ax</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_REPLACE('abcd', '.', 'x', 3, 1)`</td>
>       <td>abxd</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_REPLACE('abcd', '(b(.))', '-\2-')`</td>
>       <td>a-c-d</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] REGEXP\_SUBSTR (expr, regex \[, position \[, occurrence \[, mode \[,group]]]])
>
> Returns the portion of the `expr` string that matched `regex`.
> An empty string is returned if no match is found.
>
> The `regex` parameter is the regular expression to try to match.
> It must be a string-literal with 256 characters or fewer.  Generally,
> POSIX-compliant regular expressions are supported for `regex`.
> The escape character used to match wildcards in the `expr` literally
> is `\`.  See `REGEXP_LIKE` for more regular expression examples.
>
> The optional `position` parameter specifies where to start searching
> in `expr` for the first match.  The first character in the string
> has a `position` of `1` (the default).
>
> The optional `occurrence` parameter specifies which occurrence of
> the `regex` match is desired.  For example, `2` would return the
> second occurrence of `regex` in `expr`.  Matches do not overlap,
> so the start of a future match must start after the end of the
> previous match.
>
> The optional `mode` parameter is a string which can be empty
> (the default) for the default behavior.  See `REGEXP_LIKE` for the
> list of supported mode flags.
>
> The optional `group` parameter specifies which regular expression
> grouping (i.e., parentheses inside `regex`) to use.  The default of
> `0` uses the entire matched expression, while a `group` of `1`
> through `9` corresponds to the 1st group up through the 9th group of
> the match.
>
> Examples of `REGEXP_SUBSTR`:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`REGEXP_SUBSTR('abcdefg', 'b.')`</td>
>       <td>bc</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_SUBSTR('abcadeafghij', 'a...', 2, 1)`</td>
>       <td>adea</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_SUBSTR('abcadeafghij', 'a...', 1, 2)`</td>
>       <td>afgh</td>
>     </tr>
>
>     <tr>
>       <td>`REGEXP_SUBSTR('abcdefg', '(C(.(.)))', 1, 1, 'i', 3)`</td>
>       <td>e</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] REPLACE(expr, match, repl)
>
> Replaces every occurrence of `match` in `expr` with `repl`

> [accordion] REPLACE\_CHAR(expr, match, repl)
>
> Replaces every occurrence of the single-byte character `match` in
> `expr` with the single-byte character `repl`

> [accordion] REPLACE\_TRUNCATE(expr, match, repl)
>
> Replaces every occurrence of `match` in `expr` with `repl`, and
> then truncates the resulting string at 256 bytes if it is longer than
> that
>
> > [!NOTE]
> >
> > `REPLACE_TRUNCATE` will not work if any parameter is an
> > unrestricted-width string.
>
> > [!WARNING]
> >
> > The use of multi-byte characters in this function may
> > have unexpected results.

> [accordion] REVERSE(expr)
>
> Returns `expr` with the order of bytes reversed.
>
> > [!WARNING]
> >
> > The use of multi-byte characters in this function may
> > have unexpected results.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`REVERSE('Reverse')`</td>
>       <td>`esreveR`</td>
>     </tr>
>
>     <tr>
>       <td>`REVERSE('Was it a bat I saw?')`</td>
>       <td>`?was I tab a ti saW`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] RIGHT(expr, num\_bytes)
>
> Returns the rightmost `num_bytes` bytes from `expr`

> [accordion] RPAD(expr, length, pad)
>
> Right pads the given `expr` string with the `pad` string
> to the given `length` of bytes. If `expr` is longer than
> `length`, the return value is shortened to `length` bytes. If
> `length` is larger than 256, it will be truncated to 256 bytes.  The
> default padding character is a space.
>
> > [!WARNING]
> >
> > The use of multi-byte characters in this function may
> > have unexpected results.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`RPAD('test', 9, 'pad')`</td>
>       <td>`testpadpa`</td>
>     </tr>
>
>     <tr>
>       <td>`RPAD('test', 3, 'pad')`</td>
>       <td>`tes`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] RTRIM(expr)
>
> Removes whitespace from the right side of `expr`

> [accordion] SIZE\_PRETTY(expr)
>
> Convert the byte count `expr` into a human-readable size
> string using 1024-based units (`bytes`, `KB`, `MB`,
> `GB`, `TB`, `PB`).  The unit is selected so the printed
> number should have at most 3 digits.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`SIZE_PRETTY(2048)`</td>
>       <td>`'2 KB'`</td>
>     </tr>
>
>     <tr>
>       <td>`SIZE_PRETTY(10485760)`</td>
>       <td>`'10 MB'`</td>
>     </tr>
>
>     <tr>
>       <td>`SIZE_PRETTY(1073741824)`</td>
>       <td>`'1 GB'`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] SOUNDEX(expr)
>
> Returns a soundex value from `expr`. Only the first word in the
> string will be considered in the calculation.
>
> > [!NOTE]
> >
> > This is the algorithm used by most programming languages.

> [accordion] SPACE(n)
>
> Returns a string consisting of `n` space characters. The value of
> `n` can only be within the range of 0-256.

> [accordion] SPLIT(expr, delim, group\_num)
>
> Splits `expr` into groups delimited by the `delim` single-byte
> character and returns the `group_num` split group.  If `group_num`
> is positive, groups will be counted from the beginning of `expr`; if
> negative, groups will be counted from the end of `expr` going
> backwards.  Two consecutive delimiters will result in an empty string
> being added to the list of selectable groups.  If no instances of
> `delim` exist in `expr`, the entire string is available at group
> `1` (and `-1`).  Group `0` returns nothing.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`SPLIT('apple', 'p', 1)`</td>
>       <td>`a`</td>
>     </tr>
>
>     <tr>
>       <td>`SPLIT('apple', 'p', 2)`</td>
>       <td>*\<empty string>*</td>
>     </tr>
>
>     <tr>
>       <td>`SPLIT('apple', 'p', -1)`</td>
>       <td>`le`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] STARTS\_WITH(match, expr)
>
> Returns `1` if `expr` starts with `match` by
> string-literal comparison; otherwise, returns `0`

> [accordion] STRCMP(expr\_a, expr\_b)
>
> Compares `expr_a` to `expr_b` in a lexicographical sort
>
> <table>
>   <thead>
>     <tr>
>       <th>Situation</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`expr_a` and `expr_b` are the same</td>
>       <td>`0`</td>
>     </tr>
>
>     <tr>
>       <td>`expr_a` comes before `expr_b`, lexicographically</td>
>       <td>`-1`</td>
>     </tr>
>
>     <tr>
>       <td>`expr_a` comes after `expr_b`, lexicographically</td>
>       <td>`1`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] SUBSTR(expr, start\_pos\[, num\_chars])
>
> Alias for `SUBSTRING`

> [accordion] SUBSTRING(expr, start\_pos\[, num\_bytes])
>
> Returns `num_bytes` bytes from the `expr`, starting at the 1-based
> `start_pos` byte.  If `num_bytes` is not specified, all bytes
> after `start_pos` will be returned.
>
> > [!WARNING]
> >
> > The use of multi-byte characters in this function may
> > have unexpected results.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`SUBSTRING('banana', 3)`</td>
>       <td>`nana`</td>
>     </tr>
>
>     <tr>
>       <td>`SUBSTRING('banana', 3, 2)`</td>
>       <td>`na`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] TO\_HEX(expr\[, minimum\_digits])
>
> Alias for `HEX`

> [accordion] TRIM(expr)
>
> Removes whitespace from both sides of `expr`

> [accordion] UCASE(expr)
>
> Converts `expr` to uppercase

> [accordion] UNHEX(expr)
>
> Convert the hexadecimal string `expr` into a (decimal) number.
>
> Examples:
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`UNHEX('42')`</td>
>       <td>`66`</td>
>     </tr>
>
>     <tr>
>       <td>`UNHEX('1A')`</td>
>       <td>`26`</td>
>     </tr>
>
>     <tr>
>       <td>`UNHEX('1a')`</td>
>       <td>`26`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] UPPER(expr)
>
> Alias for `UCASE`

#### Aggregate Functions

The following functions can be used on *string* columns within
[aggregations](https://docs.kinetica.com/content/concepts/expressions.md#aggregate-expressions-label).

These functions can be used to convert string column values into delimited lists
of those values.

> [accordion] STRING\_AGG(expr\[, delim])
>
> Combines column values within a group into a single delimited *string* of those values.
>
> The default delimiter is a comma.

> [accordion] STRING\_AGG\_DISTINCT(expr\[, delim])
>
> Combines column values within a group into a single delimited *string* of those values,
> removing any duplicates.
>
> The default delimiter is a comma.

### User/Security Functions

> [accordion] CURRENT\_SCHEMA()
>
> Returns the default schema of the current user

> [accordion] CURRENT\_USER()
>
> Alias for `USER`

> [accordion] HASH(column\[, seed])
>
> Returns a non-negative integer representing an obfuscated version
> of `column`, using the given `seed`; default `seed` is `0`

> [accordion] IS\_MEMBER(role\[, user/role])
>
> Returns whether the current user (or the given `user/role`,
> if specified) has been assigned the given `role`, either
> directly or indirectly:
>
> <table>
>   <thead>
>     <tr>
>       <th>Situation</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>Current user (or given `user/role`) has been granted `role`</td>
>       <td>`true`</td>
>     </tr>
>
>     <tr>
>       <td>Current user (or given `user/role`) has not been granted `role`</td>
>       <td>`false`</td>
>     </tr>
>
>     <tr>
>       <td>Role `role` does not exist</td>
>       <td>*null*</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] IS\_ROLEMEMBER(role\[, user/role])
>
> Alias for `IS_MEMBER`

> [accordion] MASK(expr, start, length\[, char])
>
> Masks `length` bytes of `expr`, beginning at the byte position
> identified by `start`, with `*` characters (or the single-byte
> character specified in `char`):
>
> > [!WARNING]
> >
> > The use of multi-byte characters in this function may
> > have unexpected results.
>
> <table>
>   <thead>
>     <tr>
>       <th>Function Call</th>
>       <th>Result</th>
>     </tr>
>   </thead>
>
>   <tbody>
>     <tr>
>       <td>`MASK('Characters', 4, 5)`</td>
>       <td>`Cha*****rs`</td>
>     </tr>
>
>     <tr>
>       <td>`MASK('Characters', 5, 2, '#')`</td>
>       <td>`Char##ters`</td>
>     </tr>
>   </tbody>
> </table>

> [accordion] NEW\_UUID()
>
> Returns a randomly-generated UUID

> [accordion] OBFUSCATE(column\[, seed])
>
> Alias for `HASH`

> [accordion] SHA256(expr)
>
> Returns the hex digits of the SHA-256 hash of the given value
> `expr` as a `char64` string.

> [accordion] SYSTEM\_USER()
>
> Alias for `USER`

> [accordion] USER()
>
> Returns the username of the current user

## Column Expressions

Many of the functions above accept expressions as inputs in place of column
names for selecting data from [tables](https://docs.kinetica.com/content/concepts/tables.md#table) e.g.
[/aggregate/minmax](https://docs.kinetica.com/content/api/rest/aggregate_minmax_rest.md).  Given below are some examples of column
expressions:

```
(x + y)
(2 * col1) + col2
```

## Filter Expressions

Data can be filtered with the use of *filter expressions* within many endpoints;
e.g., [/filter](https://docs.kinetica.com/content/api/rest/filter_rest.md).  These expressions may contain
*column expressions* as well as tests for equality/inequality for selecting
records from the database.  A *filter expression* cannot contain
aggregation functions and should evaluate to a logical value
( *true* or *false* ).  When the result of an expression evaluation is a
numerical value, the result is converted to a logical value as follows:  `0`
is considered *false* and any other value is considered as *true*.  Some
examples of *filter expressions* are given below:

```
(x > y)
(a != b) or (c = d)
(timestamp > 1456749296789) and (x <= 10.0)
ABS(timestamp - 1456749296789) < 60 * 60 * 1000
QUARTER(timestamp) = 1 and MOD(YEAR(timestamp), 4) = 0
msg_id == 'MSGID1'
(x = 5) and y in (10,20,30)
```

## Aggregate Expressions

Some endpoints accept *aggregation expressions* as inputs for selecting
data from [tables](https://docs.kinetica.com/content/concepts/tables.md#table), e.g., [/aggregate/groupby](https://docs.kinetica.com/content/api/rest/aggregate_groupby_rest.md).  Such
expressions can only contain aggregation functions and non-nested functions of
aggregation functions.

Aggregation functions include:

* [Array Aggregation Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-array-agg)
* [Geometry Aggregation Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-geo-aggregation)
* [JSON Aggregation Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-json-agg)
* [Lookup/Grouping Aggregation Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-lookup-agg)
* [Math Aggregation Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-math-agg)
* [String Aggregation Functions](https://docs.kinetica.com/content/concepts/expressions.md#expression-functions-string-agg)

### Lookup/Grouping Functions

> [accordion] ARG\_MAX(agg\_expr, ret\_expr)
>
> The value of `ret_expr` where `agg_expr` is the maximum value (e.g. `ARG_MAX(cost, product_id)`
> returns the product ID of the highest cost product). `ARG_MAX(a, b)` is equivalent to `LAST(b, a)`.

> [accordion] ARG\_MIN(agg\_expr, ret\_expr)
>
> The value of `ret_expr` where `agg_expr` is the minimum value (e.g. `ARG_MIN(cost, product_id)`
> returns the product ID of the lowest cost product). `ARG_MIN(a, b)` is equivalent to `FIRST(b, a)`.

> [accordion] FIRST(ret\_expr, agg\_expr)
>
> The value of `ret_expr` where `agg_expr` is the minimum value (e.g. `FIRST(product_id, cost)`
> returns the product ID of the lowest cost product). `FIRST(a, b)` is equivalent to `ARG_MIN(b, a)`.

> [accordion] GROUPING(expr)
>
> Used primarily with [Rollup](https://docs.kinetica.com/content/concepts/rollup.md), [Cube](https://docs.kinetica.com/content/concepts/cube.md), and
> [Grouping Sets](https://docs.kinetica.com/content/concepts/grouping_sets.md), to distinguish the source of *null* values in an aggregated result
> set, returns whether `expr` is part of the aggregation set used to calculate the values in a given
> result set row.  Returns `0` if `expr` is part of the row's aggregation set, `1` if `expr` is
> not (meaning that aggregation took place across all `expr` values).
>
> For example, in a `ROLLUP(A)` operation, there will be two potential rows with *null* in the result
> set for column `A`.  One row will contain *null* values of `A` aggregated together, and the other
> will contain *null*, but be an aggregation over the entire table, irrespective of `A` values.  In
> this case, `GROUPING(A)` will return `0` for the *null* values of `A` aggregated together (as
> well as all other grouped `A` values) and `1` for the row resulting from aggregating across all
> `A` values.

> [accordion] LAST(ret\_expr, agg\_expr)
>
> The value of `ret_expr` where `agg_expr` is the maximum value (e.g. `LAST(product_id, cost)`
> returns the product ID of the highest cost product). `LAST(a, b)` is equivalent to `ARG_MAX(b, a)`.

## Short-Circuiting

The logical operators `and` & `or` implement a version of boolean
short-circuiting where if either side of the expression encounters an error
(divide-by-zero, etc.) but the other side evaluates to a value that alone would
determine the overall value of the logical expression, the error will be ignored
and the logical value returned:

* If one side of an `and` evaluates to *false* and the other side evaluates to
  an error, *false* will be returned.
* If one side of an `or` evaluates to *true* and the other side evaluates to
  an error, *true* will be returned.

In the normal case, both sides of either of these operators would be evaluated
simultaneously.  However, to allow these operators to be used to check for error
conditions, if an error is encountered on either side but the other side is
enough information to determine the overall value of the expression, the error
will be ignored.

This same behavior applies to the evaluation branches of the following
functions:

* `IF`
* `NVL`
* `NVL2`

It also applies to
[SQL conditional functions](https://docs.kinetica.com/content/sql/query/conditional-functions.md#sql-conditional-functions).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.