Fix for #19

Here's the PR for issue #19 (only tested with postgres, you probably want to test it against others databases)