Skip to content

Commit a4fcbbe

Browse files
authored
Upgrade pgx to 5.7.1 (#212)
1 parent 2a76105 commit a4fcbbe

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ require (
1414
github.com/hamba/avro/v2 v2.26.0
1515
github.com/jackc/pgerrcode v0.0.0-20240316143900-6e2875d9b438
1616
github.com/jackc/pglogrepl v0.0.0-20240307033717-828fbfe908e9
17-
github.com/jackc/pgx/v5 v5.6.0
17+
github.com/jackc/pgx/v5 v5.7.1
1818
github.com/matryer/is v1.4.1
1919
golang.org/x/tools v0.26.0
2020
gopkg.in/tomb.v2 v2.0.0-20161208151619-d5d1b5820637

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsI
224224
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
225225
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
226226
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
227-
github.com/jackc/pgx/v5 v5.6.0 h1:SWJzexBzPL5jb0GEsrPMLIsi/3jOo7RHlzTjcAeDrPY=
228-
github.com/jackc/pgx/v5 v5.6.0/go.mod h1:DNZ/vlrUnhWCoFGxHAG8U2ljioxukquj7utPDgtQdTw=
227+
github.com/jackc/pgx/v5 v5.7.1 h1:x7SYsPBYDkHDksogeSmZZ5xzThcTgRz++I5E+ePFUcs=
228+
github.com/jackc/pgx/v5 v5.7.1/go.mod h1:e7O26IywZZ+naJtWWos6i6fvWK+29etgITqrqHLfoZA=
229229
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
230230
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
231231
github.com/jgautheron/goconst v1.7.1 h1:VpdAG7Ca7yvvJk5n8dMwQhfEZJh95kl/Hl9S1OI5Jkk=

source/logrepl/internal/relationset.go

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,15 +65,9 @@ func (rs *RelationSet) Values(id uint32, row *pglogrepl.TupleData) (map[string]a
6565
// assert same number of row and rel columns
6666
for i, tuple := range row.Columns {
6767
col := rel.Columns[i]
68-
decoder := rs.oidToCodec(col.DataType)
69-
val, err := decoder.DecodeValue(rs.connInfo, col.DataType, pgtype.TextFormatCode, tuple.Data)
70-
if err != nil {
71-
return nil, fmt.Errorf("failed to decode tuple %d: %w", i, err)
72-
}
73-
74-
v, err := types.Format(col.DataType, val)
75-
if err != nil {
76-
return nil, fmt.Errorf("failed to format column %q type %T: %w", col.Name, val, err)
68+
v, decodeErr := rs.decodeValue(col, tuple.Data)
69+
if decodeErr != nil {
70+
return nil, fmt.Errorf("failed to decode value for column %q: %w", col.Name, err)
7771
}
7872

7973
values[col.Name] = v
@@ -89,3 +83,30 @@ func (rs *RelationSet) oidToCodec(id uint32) pgtype.Codec {
8983
}
9084
return dt.Codec
9185
}
86+
87+
func (rs *RelationSet) decodeValue(col *pglogrepl.RelationMessageColumn, data []byte) (any, error) {
88+
decoder := rs.oidToCodec(col.DataType)
89+
// This workaround is due to an issue in pgx v5.7.1.
90+
// Namely, that version introduces an XML codec
91+
// (see: https://github.com/jackc/pgx/pull/2083/files#diff-8288d41e69f73d01a874b40de086684e5894da83a627e845e484b06d5e053a44).
92+
// The XML codec, however, always return nil when deserializing input bytes
93+
// (see: https://github.com/jackc/pgx/pull/2083#discussion_r1755768269).
94+
var val any
95+
var err error
96+
if col.DataType == pgtype.XMLOID || col.DataType == pgtype.XMLArrayOID {
97+
val, err = decoder.DecodeDatabaseSQLValue(rs.connInfo, col.DataType, pgtype.TextFormatCode, data)
98+
} else {
99+
val, err = decoder.DecodeValue(rs.connInfo, col.DataType, pgtype.TextFormatCode, data)
100+
}
101+
102+
if err != nil {
103+
return nil, fmt.Errorf("failed to decode value of pgtype %v: %w", col.DataType, err)
104+
}
105+
106+
v, err := types.Format(col.DataType, val)
107+
if err != nil {
108+
return nil, fmt.Errorf("failed to format column %q type %T: %w", col.Name, val, err)
109+
}
110+
111+
return v, nil
112+
}

source/types/types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ func Format(oid uint32, v any) (any, error) {
4242
return Time.Format(t)
4343
case *time.Time:
4444
return Time.Format(*t)
45+
case []uint8:
46+
if oid == pgtype.XMLOID {
47+
return string(t), nil
48+
}
49+
return t, nil
4550
default:
4651
return t, nil
4752
}

0 commit comments

Comments
 (0)