Introducing PopSQL + dbt. The first SQL editor with built-in dbt supportRead more →

How to Write a Case Statement in PostgreSQL

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

    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;

Ready for a modern SQL editor?