Updated ruby script and queries for postgresql