Original issue https://github.com/jackc/pgtype/issues/68
This crash occurred in the recursive assignment system used to support
multidimensional arrays.
This was fixed in 9639a69d451f55456f598c1aa8b93053f8df3088. However,
that fix incorrectly used nil instead of an empty slice.
In hindsight, it appears the fundamental error is that an assignment to
a slice of a type that is not specified is handled with the recursive /
reflection path. Or another way of looking at it is as an unexpected
feature where []T can now be scanned if individual elements are
assignable to T even if []T is not specifically handled.
But this new reflection / recursive path did not handle empty arrays.
This fix handles the reflection path for an empty slice by allocating an
empty slice.
There were 2 errors when using the example code:
- not enough arguments in call to pgConn.Close
- no new variables on left side of :=
With these changes, the example works again.
When nil IP is returned from net.ParseIP, it is accepted into Inet type,
but not properly marked as being Null. That introduces issues later on
when calling for example EncodeBinary, since it does not assume this can
happen.
This commit resolves that by properly detecting zero-length net.IP and
setting status to Null if that is the case.
Previously, the Scan documentation stated that scanning into a []byte
will skip the decoding process and directly copy the raw bytes received
from PostgreSQL.
This has not been true for at least 2 months. It is also undesirable
behavior in some cases such as a binary formatted jsonb. In that case
the '1' prefix needs to be stripped to have valid JSON. If the raw
bytes are desired this can easily be accomplished by scanning into
pgtype.GenericBinary or using Rows.RawValues.
In light of the fact that the new behavior is superior, and that it has
been in place for a significant amount of time, I have decided to
document the new behavior rather than change back to the old behavior.