Skip to content

Instantly share code, notes, and snippets.

@scottymac
Last active August 29, 2015 14:04
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 scottymac/a1b5837dc81f9d6f6d76 to your computer and use it in GitHub Desktop.
Save scottymac/a1b5837dc81f9d6f6d76 to your computer and use it in GitHub Desktop.
Postgres Cast an Array Column for Comparison
-- 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