openGauss Operators

·

2 min read

An operator in openGauss is a reserved keyword or character, and it is generally used in the WHERE statement as a filter condition. Common operators are as follows:

Arithmetic Operators

Description: Addition

Example:

```
openGauss=# SELECT 2+3 AS RESULT;
 result 
--------
      5
(1 row)
```
Description: Subtraction

Example:

```
openGauss=# SELECT 2-3 AS RESULT;
 result 
--------
     -1
(1 row)
```
  • *

    Description: Multiplication

    Example:

      openGauss=# SELECT 2*3 AS RESULT;
       result 
      --------
            6
      (1 row)
    
  • /

    Description: Division (The result is not rounded.)

    Example:

      openGauss=# SELECT 4/2 AS RESULT;
       result 
      --------
            2
      (1 row)
    
      openGauss=# SELECT 4/3 AS RESULT;
            result      
      ------------------
       1.33333333333333
      (1 row)
    
  • +/-

    Description: Positive/Negative

    Example:

      openGauss=# SELECT -2 AS RESULT;
       result 
      --------
           -2
      (1 row)
    
  • %

    Description: Model (to obtain the remainder)

    Example:

      openGauss=# SELECT 5%4 AS RESULT;
       result 
      --------
            1
      (1 row)
    
  • @

    Description: Absolute value

    Example:

      openGauss=# SELECT @ -5.0 AS RESULT;
       result 
      --------
          5.0
      (1 row)
    
  • ^

    Description: Power (exponent calculation)

    Example:

      openGauss=# SELECT 2.0^3.0 AS RESULT;
             result       
      --------------------
       8.0000000000000000
      (1 row)
    
  • |/

    Description: Square root

    Example:

      openGauss=# SELECT |/ 25.0 AS RESULT;
       result 
      --------
            5
      (1 row)
    
  • ||/

    Description: Cubic root

    Example:

      openGauss=# SELECT ||/ 27.0 AS RESULT;
       result 
      --------
            3
      (1 row)