Postgresql-- conditional judgment function, system function, etc.
1. Conditional judgment function:
The conditional judgment function is called the control flow function. In postgresql, the conditional judgment function is: case.
1 、 CASE expr WHEN v1 THEN r1 [WHEN v2 THEN r2] [ELSE rn] END
This function says that if the expr value is equal to a vn, it returns the result after the corresponding position THEN, and if it is not equal to all values, it returns the rn after ELSE.
Example: use the case value when statement to perform the branch operation, as follows:
Testdb=# select case 2 when 1 then 'one' when 2 then' two' else 'more' end
Case
-
Two
(1 row)
2 、 CASE WHEN v1 THEN r1 [WHEN v2 THEN r2] ELSE rn END
This function indicates that if a vn value is TRUE, the result after the corresponding position THEN will be returned. If all values are not TRUE, the rn after ELSE will be returned.
Example: use case when statements to perform branch operations, such as:
Testdb=# select case when 1