Fixed postgres vs sqlite bug

The sqlite query statement wasn't compatible with postgres so I changed it to active record syntax