Last active
August 29, 2015 14:04
-
-
Save scottymac/a1b5837dc81f9d6f6d76 to your computer and use it in GitHub Desktop.
Postgres Cast an Array Column for Comparison
This file contains hidden or 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
-- datetimes is an array column of strings (b/c ActiveRecord doesn't support arrays of datetimes just yet (but soon)) | |
-- This is doing a date comparison | |
SELECT * FROM table WHERE now() ANY (CAST(datetimes as timestamp[])) | |
in ActiveRecord: | |
scope :past, lambda { | |
where(":now > ALL (CAST(datetimes as timestamp[]))", { now: Time.zone.now }) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment