Make this query work in PostgreSQL.
Merge pull request #24 from jordandukart/7.x-PostgreSQL

Make this query work in PostgreSQL.