Fixed #131 - Added correct PostgreSQL queries