Fix #204

Add a test that triggers the bug and the fix. This bug is not triggered by the Sqlite backend but is triggered by the Postgresql backend.

All tests pass with the Postgresql and Sqlite backends.