Get the App
SLTechnology News&Howtos  ›  Database  › 

Postgresql-- conditional judgment function, system function, etc.

Shulou Source: shulou.com Published: 2022-06-01 13:48:44 09月16日 Update

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

Tags: Functions encryption characters strings examples types conditions systems data locations information branches versions users user names results codes statements binary hexadecimal Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Microsoft Huawei MySQL Xiaomi