Skip to content

Instantly share code, notes, and snippets.

@daz
Last active December 16, 2015 06:39
Show Gist options
  • Save daz/5392816 to your computer and use it in GitHub Desktop.
Save daz/5392816 to your computer and use it in GitHub Desktop.
Getting distinct years in Rails and Postgresql
# start_time is a #datetime column, Postgres stores as a timestamp, we need to use date_part to extract 'year'
Event.select("date_part('year', start_time)").uniq
# Spits out
# SELECT DISTINCT date_part('year', start_time) FROM "events"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment