6

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

2
  • The same as in most other languages: CASE expression WHEN value THEN ... ELSE WHEN value THEN ... vs. IF expression = value THEN ELSE IF expression = value THEN .... Commented Nov 7, 2013 at 9:37
  • but both can be used in a function. AN Commented Nov 7, 2013 at 9:46

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.