-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Description
I have recently have been experimenting with pg's binary mode for performance reasons and tried the latest change, and I found that it delivers incorrect results sometimes for various non-string fields.
For example, a "int32" column with value "1000" is incorrectly returned as 1007.
This is caused by the parser converting the buffer slice into an utf8 string:
fields[i] = len === -1 ? null : this.reader.string(len) |
and then the result converts it back into a buffer in binary mode
node-postgres/packages/pg/lib/result.js
Lines 69 to 70 in 1a25d12
const v = this.fields[i].format === 'binary' ? Buffer.from(rawValue) : rawValue | |
row[field] = this._parsers[i](v) |
This is incorrect, however, because roundtrips with random binary data from and to utf8, does not work all the time - for example the int32 value "1000" (0x3e8)
> Buffer.from(Buffer.from([0,0,0x03,0xe8]).toString())
<Buffer 00 00 03 ef bf bd>
> readInt32BE()
< 1007
I was able to fix this by performing the conversion the other way around, but this does not seem great performance-wise.