# Common Functions

## Mathematical Functions

<table>
    <thead>
    <tr>
        <th>Function Name</th>
        <th>Description</th>
        <th>Syntax</th>
    </tr>
    </thead>
    <tbody><tr>
        <td>plus(a, b), a + b</td>
        <td>Calculates the sum of two fields</td>
        <td>plus(table.field1, table.field2)</td>
    </tr>
    <tr>
        <td>minus(a, b), a - b</td>
        <td>Calculates the difference of two fields</td>
        <td>minus(table.field1, table.field2)</td>
    </tr>
    <tr>
        <td>multiply(a, b), a * b</td>
        <td>Calculates the product of two fields</td>
        <td>multiply(table.field1, table.field2)</td>
    </tr>
    <tr>
        <td>divide(a, b), a / b</td>
        <td>Calculates the quotient of two fields</td>
        <td>divide(table.field1, table.field2)</td>
    </tr>
    <tr>
        <td>modulo(a, b), a % b</td>
        <td>Calculates the remainder of two fields</td>
        <td>modulo(table.field1, table.field2)</td>
    </tr>
    <tr>
        <td>abs(a)</td>
        <td>Returns the absolute value</td>
        <td>abs(table.field1)</td>
    </tr>
    <tr>
        <td>negate(a)</td>
        <td>Returns the negation</td>
        <td>negate(table.field1)</td>
    </tr>
    </tbody></table>

## Comparison Functions

<table>
    <thead>
    <tr>
        <th>Function Name</th>
        <th>Description</th>
        <th>Syntax</th>
    </tr>
    </thead>
    <tbody><tr>
        <td>=, ==</td>
        <td>Checks if equal</td>
        <td>table.field1 = value</td>
    </tr>
    <tr>
        <td>!=, &lt;&gt;</td>
        <td>Checks if not equal</td>
        <td>table.field1 != value</td>
    </tr>
    <tr>
        <td>&gt;</td>
        <td>Checks if greater than</td>
        <td>table.field1 &gt; value</td>
    </tr>
    <tr>
        <td>&gt;=</td>
        <td>Checks if greater than or equal to</td>
        <td>table.field1 &gt;= value</td>
    </tr>
    <tr>
        <td>&lt;</td>
        <td>Checks if less than</td>
        <td>table.field1 &lt; value</td>
    </tr>
    <tr>
        <td>&lt;=</td>
        <td>Checks if less than or equal to</td>
        <td>table.field1 &lt;= value</td>
    </tr>
    </tbody></table>

## Logical Functions

<table>
    <thead>
    <tr>
        <th>Function Name</th>
        <th>Description</th>
        <th>Syntax</th>
    </tr>
    </thead>
    <tbody><tr>
        <td>AND</td>
        <td>Both conditions must be met</td>
        <td>-</td>
    </tr>
    <tr>
        <td>OR</td>
        <td>One of the conditions must be met</td>
        <td>-</td>
    </tr>
    <tr>
        <td>NOT</td>
        <td>Reverses the condition result</td>
        <td>-</td>
    </tr>
    </tbody></table>

## Type Conversion Functions

**Note:** Conversion functions may overflow, resulting in numbers consistent with data types in C language.

<table>
    <thead>
    <tr>
        <th>Function Name</th>
        <th>Purpose</th>
        <th>Usage Scenario</th>
    </tr>
    </thead>
    <tbody><tr>
        <td>toInt(8|16|32|64)</td>
        <td>Converts string to integer</td>
        <td>toInt8('128') results in -127</td>
    </tr>
    <tr>
        <td>toUInt(8|16|32|64)</td>
        <td>Converts string to unsigned integer</td>
        <td>toUInt8('128') results in 128</td>
    </tr>
    <tr>
        <td>toInt(8|16|32|64)OrZero</td>
        <td>Converts string to integer, returns 0 on error</td>
        <td>toInt8OrZero('a') results in 0</td>
    </tr>
    <tr>
        <td>toUInt(8|16|32|64)OrZero</td>
        <td>Converts string to integer, returns 0 on error</td>
        <td>toUInt8OrZero('a') results in 0</td>
    </tr>
    <tr>
        <td>toInt(8|16|32|64)OrNull</td>
        <td>Converts string to integer, returns NULL on error</td>
        <td>toInt8OrNull('a') results in NULL</td>
    </tr>
    <tr>
        <td>toUInt(8|16|32|64)OrNull</td>
        <td>Converts string to integer, returns NULL on error</td>
        <td>toUInt8OrNull('a') results in NULL</td>
    </tr>
    </tbody></table>

There are similar functions for floating point numbers or date types. For details, please refer to the [official documentation](https://clickhouse.com/docs/en/sql-reference/functions/type-conversion-functions/).

## Date Functions

Please refer to the [official documentation](https://clickhouse.com/docs/en/sql-reference/functions/date-time-functions/) for details.

## String Functions

Please refer to the [official documentation](https://clickhouse.tech/docs/en/query_language/functions/string_functions/) for details.

## UUID

Please refer to the [official documentation](https://clickhouse.com/docs/en/sql-reference/functions/uuid-functions/) for details.

## JSON Functions

Please refer to the [official documentation](https://clickhouse.com/docs/en/sql-reference/functions/json-functions/) for details.