Add tests for the 'wait' argument.

Fix handling of non-empty results returned by PostgreSQL in this case.