Skip to content

Instantly share code, notes, and snippets.

@ramiroaznar
Created February 14, 2017 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ramiroaznar/ca302e03fcbc6af70b64115e9fb63bd2 to your computer and use it in GitHub Desktop.
Save ramiroaznar/ca302e03fcbc6af70b64115e9fb63bd2 to your computer and use it in GitHub Desktop.
How to convert month number to month strings with PostgreSQL conditionals
SELECT *,
CASE WHEN month = 1 THEN 'January'
WHEN month = 1 THEN 'January'
WHEN month = 2 THEN 'February'
WHEN month = 3 THEN 'March'
WHEN month = 4 THEN 'April'
WHEN month = 5 THEN 'May'
WHEN month = 6 THEN 'June'
WHEN month = 7 THEN 'July'
WHEN month = 8 THEN 'August'
WHEN month = 9 THEN 'September'
WHEN month = 10 THEN 'October'
WHEN month = 11 THEN 'November'
ELSE 'December' END as month_string
FROM table_name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment