PostgreSQL's internal operators are rich in four main categories: arithmetic operators, comparison operators, logical operators, bitwise manipulation operators. As follows:
①: Arithmetic operators:
Used for various numerical operations, including plus (+) minus (-) multiplication (*) except (/) for remainder (%)
Example:
testdb=# CREATE TABLE emp (num int);
testdb=# INSERT INTO EMP values (60);
testdb=# select num,num+10,num-10,num+10-5,num+10.5 from emp; ---To fields: add and subtract operations
num |? column? |? column? |? column? |
-----+----------+----------+----------+----------
60 | 70 | 50 | 65 | 70.5
(1 row)
testdb=# select num,num*2,num/3,num%2 from emp; ---To fields: multiplication operations
num |? column? |? column? |? column?
-----+----------+----------+----------
60 | 120 | 20 | 0
(1 row)
②: comparison operator
For comparison operations, including greater than (>) less than (<) equals (=) greater than or equal (>=) less than or equal (<=) is not equal to (!). =), as well as in, between and, greatest, least, like, and so on.
Example:
testdb=# Select 1=0,2=2, (1+4) = (2+3);
? column? |? column? |?
----------+----------+----------
f | T | T
(1 row)
testdb=# select ' Good ' <> ' God ', 1<>2,5.5!=5, (+)!=2;
? column? |? column? |? column? |
----------+----------+----------+----------
T | T | T | F
(1 row)
--least operator: Judging the minimum value
The syntax format for the least operator is: least (value 1, value 2,,, value n), where the value n indicates that there are n values in the parameter list. Returns the minimum value in the case of two or more parameters. Any value is null and is ignored in comparison.
Example: using the least operator to determine size
testdb=# Select Least (2,0), least (1.5,5,3), least (' a ', ' G ', ' B '), least (10,null); ---from the following results can be seen, the return is the smallest value!!!
least | least | least | Least
-------+-------+-------+-------
0 | 1.5 | A | 10
(1 row)
--greatest (value1,value2,,,,)
Syntax Format: Greatest (value 1, value 2,,,) where n indicates that there are n values in the parameter list. When there are two or more parameters, the return value is the maximum value. Any one argument is null and is ignored in the comparison.
Example: Using the greatest operator for size judgments,
testdb=# Select Greatest (2,0), Greatest (1.5,5,3), greatest (' a ', ' G ', ' B '), greatest (10,null); ---from the following results can be seen, the return is the maximum value!!!
Greatest | Greatest | Greatest | Greatest
----------+----------+----------+----------
2 | 5 | G | 10
(1 row)
③: Logical operators
The result of the evaluation of a logical operator is T (true), F (false), which has logical non (not) logic with (and) logic or (OR)
④: Bitwise manipulation Operators
Operands that participate in the operation are calculated by bits, including bits and (&), bit or (|) bit non (~) shift Left (<<) Shift Right (>>)
Attention:
The precedence of an operation determines the order in which different operators are evaluated in an expression. Lowest: =,:= Highest! In general, the high-level operations Mr. Foo are calculated, and if the levels are the same, PostgreSQL is evaluated from left to right in the order of the expressions.
postgresql--operator Introduction