Ran into problems with too long command lines for psql. The fix has poor performance...