diff --git a/pgtype.go b/pgtype.go index 5aa466d2..df5078a9 100644 --- a/pgtype.go +++ b/pgtype.go @@ -779,7 +779,7 @@ func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, dst interface{}) Scan } case *[]byte: switch oid { - case ByteaOID, TextOID, VarcharOID: + case ByteaOID, TextOID, VarcharOID, JSONOID: return scanPlanBinaryBytes{} } case BinaryDecoder: @@ -789,6 +789,10 @@ func (ci *ConnInfo) PlanScan(oid uint32, formatCode int16, dst interface{}) Scan switch dst.(type) { case *string: return scanPlanString{} + case *[]byte: + if oid != ByteaOID { + return scanPlanBinaryBytes{} + } case TextDecoder: return scanPlanDstTextDecoder{} } diff --git a/pgtype_test.go b/pgtype_test.go index 0c2bec83..32ce0a99 100644 --- a/pgtype_test.go +++ b/pgtype_test.go @@ -79,6 +79,14 @@ func TestConnInfoScanTextFormatInterfacePtr(t *testing.T) { assert.Equal(t, "foo", got) } +func TestConnInfoScanTextFormatNonByteaIntoByteSlice(t *testing.T) { + ci := pgtype.NewConnInfo() + var got []byte + err := ci.Scan(pgtype.JSONBOID, pgx.TextFormatCode, []byte("{}"), &got) + require.NoError(t, err) + assert.Equal(t, []byte("{}"), got) +} + func TestConnInfoScanBinaryFormatInterfacePtr(t *testing.T) { ci := pgtype.NewConnInfo() var got interface{}