Skip to content

Commit 63422c7

Browse files
revert change in if
1 parent 5c1fbf4 commit 63422c7

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pgtype/json.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ type scanPlanJSONToJSONUnmarshal struct {
197197
}
198198

199199
func (s *scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst any) error {
200-
if src == nil || string(src) == "null" {
200+
if src == nil {
201201
dstValue := reflect.ValueOf(dst)
202202
if dstValue.Kind() == reflect.Ptr {
203203
el := dstValue.Elem()

pgtype/json_test.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,7 @@ func TestJSONCodecScanNull(t *testing.T) {
335335
require.Contains(t, err.Error(), "cannot scan NULL into *struct {}")
336336

337337
err = conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&dest)
338-
require.Error(t, err)
339-
require.Contains(t, err.Error(), "cannot scan NULL into *struct {}")
338+
require.NoError(t, err)
340339

341340
var destPointer *struct{}
342341
err = conn.QueryRow(ctx, "select null::jsonb").Scan(&destPointer)
@@ -346,6 +345,10 @@ func TestJSONCodecScanNull(t *testing.T) {
346345
err = conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&destPointer)
347346
require.NoError(t, err)
348347
require.Nil(t, destPointer)
348+
349+
var raw json.RawMessage
350+
require.NoError(t, conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&raw))
351+
require.Equal(t, json.RawMessage("null"), raw)
349352
})
350353
}
351354

0 commit comments

Comments
 (0)