Last active
December 16, 2015 06:39
-
-
Save daz/5392816 to your computer and use it in GitHub Desktop.
Getting distinct years in Rails and Postgresql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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