Operators
Tags: beginners, opengauss, sql
Published: 2023-03-06 03:59:40

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

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ysk39buuc9d2fhvde5sb.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/66c4df7ucb66fn0zbrw1.png)

**·** *

Description: Multiplication

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8kyvpxdk4qv7ygg37fw.png)

**·** /

Description: Division (The result is not rounded.)

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1s75yrho0bdcxkw9il7n.png)

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4lkvogea6hcvko2b8hv8.png)

**·** +/-

Description: Positive/Negative

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ro3furds4s62t57evrv6.png)

**·** %

Description: Model (to obtain the remainder)

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1x8rgkru1ofqaipmjmfc.png)

**·** @

Description: Absolute value

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8n1y8zstktr92gugeuuf.png)

**·** ^

Description: Power (exponent calculation)

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eqku1zjajve35jktaruc.png)

**·** |/

Description: Square root

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cp5dwj4fyhjcfmf4z8gv.png)

**·** ||/

Description: Cubic root

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/peaydb0sclozpepvyzy5.png)

**·** !

Description: Factorial

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1y3tuek490jt0yidehff.png)

**·** !!

Description: Factorial (prefix operator)

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/v0ndd3zzdl30jppxm8ln.png)

**·** &

Description: Binary AND

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sq64kfupw43od47cpcru.png)

**·** |

Description: Binary OR

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lze7a97df1n1n0gzd7fj.png)

**·** #

Description: Binary XOR

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0w7jjhjol0pu80fkp9ok.png)

**·** ~

Description: Binary NOT

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j8q2ezay8khp829i0z78.png)

**·** <<

Description: Binary shift left

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r20putkb459y24abcidh.png)

**·** >>

Description: Binary shift right

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pi7ukoh5urjyi12fmro8.png)

**Comparison Operators**

Comparison operators are available for the most data types and return Boolean values.

All comparison operators are binary operators. Only data types that are the same or that can be implicitly converted can be compared by using comparison operators.

Table 1 describes the comparison operators provided by openGauss.

Table 1 Comparison operators

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ll6a247z9ecuchmbkbxi.png)

Comparison operators are available for all relevant data types. All comparison operators are binary operators that returned values of Boolean type. The calculation priority of the inequality sign is higher than that of the equality sign. If the entered data is different and cannot be implicitly converted, the comparison fails. For example, an expression such as 1<2<3 is invalid because the less-than sign (<) cannot be used to compare Boolean values and 3.

Example:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qtqnkanlrzgixjj0og1i.png)

**Logical Operators**

Common logical operators include AND, OR, and NOT. The operation result can be TRUE, FALSE, or NULL (which means unknown). Their priorities are NOT > AND > OR.

The operators AND and OR are commutative. That is, you can switch the left and right operand without affecting the result.

Table 2 lists the calculation rules, where a and b represent logical expressions.

Table 2 Operation rules

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/awdxfx612ngtrx232lrw.png)