Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgres functions : difference between CASE WHEN and IF ELSE

Tags:

sql

postgresql

Can any one let me know what the differences are between WHEN CASE .. and IF/ELSE when writing in Postgres functions.

like image 470
Débora Avatar asked Nov 12 '22 19:11

Débora


1 Answers

The problem is which CASE do you mean?

One CASE is an expression. It can appear inside expressions, like A + CASE ... + B. Along with COALESCE, NULLIF, GREATEST and LEAST it makes the group of conditional expressions.

The other CASE, along with IF, is a control structure (a conditional). It can appear in the SQL control flow to chose what blocks/statements are executed, based on a condition.

like image 122
Remus Rusanu Avatar answered Nov 15 '22 06:11

Remus Rusanu