Started working on postgres queries

Still a WIP, maybe a good milestone though.