diff --git a/pgtype/array_codec.go b/pgtype/array_codec.go index 56393eb0..d7ccf0aa 100644 --- a/pgtype/array_codec.go +++ b/pgtype/array_codec.go @@ -303,7 +303,7 @@ func (c *ArrayCodec) decodeText(m *Map, arrayOID uint32, src []byte, array Array for i, s := range uta.Elements { elem := array.ScanIndex(i) var elemSrc []byte - if s != "NULL" { + if s != "NULL" || uta.Quoted[i] { elemSrc = []byte(s) } diff --git a/pgtype/array_codec_test.go b/pgtype/array_codec_test.go index f90995b3..797a5768 100644 --- a/pgtype/array_codec_test.go +++ b/pgtype/array_codec_test.go @@ -318,3 +318,27 @@ func TestArrayCodecEncodeMultipleDimensionsRagged(t *testing.T) { defer rows.Close() }) } + +// https://github.com/jackc/pgx/issues/1494 +func TestArrayCodecDecodeTextArrayWithTextOfNULL(t *testing.T) { + defaultConnTestRunner.RunTest(context.Background(), t, func(ctx context.Context, t testing.TB, conn *pgx.Conn) { + { + var actual []string + err := conn.QueryRow(ctx, `select '{"foo", "NULL", " NULL "}'::text[]`).Scan(&actual) + require.NoError(t, err) + require.Equal(t, []string{"foo", "NULL", " NULL "}, actual) + } + + { + var actual []pgtype.Text + err := conn.QueryRow(ctx, `select '{"foo", "NULL", NULL, " NULL "}'::text[]`).Scan(&actual) + require.NoError(t, err) + require.Equal(t, []pgtype.Text{ + {String: "foo", Valid: true}, + {String: "NULL", Valid: true}, + {}, + {String: " NULL ", Valid: true}, + }, actual) + } + }) +}