From 63422c7d6cfe092af402f48e16729acd1e3bae1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20R=C3=B6hrich?= Date: Mon, 24 Mar 2025 15:01:22 +0100 Subject: [PATCH] revert change in if --- pgtype/json.go | 2 +- pgtype/json_test.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pgtype/json.go b/pgtype/json.go index 6f7ebb51..60aa2b71 100644 --- a/pgtype/json.go +++ b/pgtype/json.go @@ -197,7 +197,7 @@ type scanPlanJSONToJSONUnmarshal struct { } func (s *scanPlanJSONToJSONUnmarshal) Scan(src []byte, dst any) error { - if src == nil || string(src) == "null" { + if src == nil { dstValue := reflect.ValueOf(dst) if dstValue.Kind() == reflect.Ptr { el := dstValue.Elem() diff --git a/pgtype/json_test.go b/pgtype/json_test.go index ebe144aa..e1d654f2 100644 --- a/pgtype/json_test.go +++ b/pgtype/json_test.go @@ -335,8 +335,7 @@ func TestJSONCodecScanNull(t *testing.T) { require.Contains(t, err.Error(), "cannot scan NULL into *struct {}") err = conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&dest) - require.Error(t, err) - require.Contains(t, err.Error(), "cannot scan NULL into *struct {}") + require.NoError(t, err) var destPointer *struct{} err = conn.QueryRow(ctx, "select null::jsonb").Scan(&destPointer) @@ -346,6 +345,10 @@ func TestJSONCodecScanNull(t *testing.T) { err = conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&destPointer) require.NoError(t, err) require.Nil(t, destPointer) + + var raw json.RawMessage + require.NoError(t, conn.QueryRow(ctx, "select 'null'::jsonb").Scan(&raw)) + require.Equal(t, json.RawMessage("null"), raw) }) }