First, we try to convert the field to a value of type "b", if that fails then we try to convert the field to a value of type "a"
Untested at this point, and I know it has a few bugs and possible bugs: 1. If the correct OID/typenames aren't in the cache, getTypename will attempt to fetch the OID from the database when libpq is busy. There are a couple possible fixes: A. Fetch all oids at connection startup. B. Buffer results until the connection becomes available, then fetch oids. This breaks the resource usage of fold, though. Resource usage might be moot at this stage anyway. I believe that the database backend sends results eagerly, i.e. potentially faster than the fold can consume them. Maybe I should study Takusen. Does it create a cursor for fetching results incrementally? C. establish another connection to fetch the typename/oid pairs 2. There likely problems with exceptions, that might cause a connection to be rendered unusable.