Updated on 2025-08-25 GMT+08:00

Simple Expressions

Logical Expressions

For details about the operators and calculation rules of logical expressions, refer to Logical Operators.

Comparison Expressions

Commonly used comparison operators can be found in Comparison Operators.

In addition to comparison operators, the following structures can also be used:

  • BETWEEN operator

    a BETWEEN x AND y is equivalent to a >= x AND a <= y.

    a NOT BETWEEN x AND y is equivalent to a < x OR a > y.

  • To check whether a value is null, use:

    expression IS NULL

    expression IS NOT NULL

    Or equivalent structures, though non-standard:

    expression ISNULL

    expression NOTNULL

    Do not write expression=NULL or expression<>(!=)NULL, as NULL represents an unknown value, making it impossible to determine equality between two unknowns with such expressions.

Example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
postgres=#SELECT 2 BETWEEN 1 AND 3 AS RESULT;
 result 
----------
 t
(1 row)

postgres=#SELECT 2 >= 1 AND 2 <= 3 AS RESULT;
 result 
----------
 t
(1 row)

postgres=#SELECT 2 NOT BETWEEN 1 AND 3 AS RESULT;
 result 
----------
 f
(1 row)

postgres=#SELECT 2 < 1 OR 2 > 3 AS RESULT;
 result 
----------
 f
(1 row)

postgres=#SELECT 2+2 IS NULL AS RESULT;
 result 
----------
 f
(1 row)

postgres=#SELECT 2+2 IS NOT NULL AS RESULT;
 result 
----------
 t
(1 row)

postgres=#SELECT 2+2 ISNULL AS RESULT;
 result 
----------
 f
(1 row)

postgres=#SELECT 2+2 NOTNULL AS RESULT;
 result 
----------
 t
(1 row)

postgres=#SELECT 2+2 IS DISTINCT FROM NULL AS RESULT;
 result 
----------
 t
(1 row)

postgres=#SELECT 2+2 IS NOT DISTINCT FROM NULL AS RESULT;
 result  
----------
 f
(1 row)