Factor out common bits of postgres/sqlite into norm.common
Attempt at postgres working