Fix postgresql primary key issues

This closes issue #37