Merge pull request #2288 from felix-roehrich/fr/fix-plan-scan

Revert change in `if` from #2236.
master
Jack Christensen 2025-03-24 19:46:22 -05:00 committed by GitHub
commit 0e0a7d8344
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 3 deletions

View File

@ -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()

View File

@ -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)
})
}