Remove unnecessary whitespace
Reformat error handling code

* Move error handling closer to error assignment
* Collapse deep conditionals so things are easier to read
* Change explicit (and often unnecessary) 'var err' declarations to implicit 'err :='
Minor cleanups in postgresql