Fix sometimes failing tests (fixes #1407).
Merge pull request #1452 from gittip/postgres-internalerror

Fix sometimes failing tests (fixes #1407).