PostgreSQL

How to Write a Case Statement in PostgreSQL

Case statements are useful when you’re reaching for an if statement in your select clause.

select
  case
    when precipitation = 0 then 'none'
    when precipitation <= 5 then 'little'
    when precipitation > 5 then 'lots'
    else 'unknown'
  end as amount_of_rain
from weather_data;