diff --git a/pgtype/xml.go b/pgtype/xml.go
index 79e3698a..1d159cf1 100644
--- a/pgtype/xml.go
+++ b/pgtype/xml.go
@@ -192,7 +192,7 @@ func (c *XMLCodec) DecodeValue(m *Map, oid uint32, format int16, src []byte) (an
return nil, nil
}
- var dst any
- err := c.Unmarshal(src, &dst)
- return dst, err
+ dstBuf := make([]byte, len(src))
+ copy(dstBuf, src)
+ return dstBuf, nil
}
diff --git a/pgtype/xml_test.go b/pgtype/xml_test.go
index 0f755e96..21185914 100644
--- a/pgtype/xml_test.go
+++ b/pgtype/xml_test.go
@@ -97,3 +97,32 @@ func TestXMLCodecPointerToPointerToString(t *testing.T) {
require.Nil(t, s)
})
}
+
+func TestXMLCodecDecodeValue(t *testing.T) {
+ skipCockroachDB(t, "CockroachDB does not support XML.")
+ defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, _ testing.TB, conn *pgx.Conn) {
+ for _, tt := range []struct {
+ sql string
+ expected any
+ }{
+ {
+ sql: `select 'bar'::xml`,
+ expected: []byte("bar"),
+ },
+ } {
+ t.Run(tt.sql, func(t *testing.T) {
+ rows, err := conn.Query(ctx, tt.sql)
+ require.NoError(t, err)
+
+ for rows.Next() {
+ values, err := rows.Values()
+ require.NoError(t, err)
+ require.Len(t, values, 1)
+ require.Equal(t, tt.expected, values[0])
+ }
+
+ require.NoError(t, rows.Err())
+ })
+ }
+ })
+}