Updating query to work with both Postgres and Oracle