jackc / pgtype

MIT License
300 stars 111 forks source link

lseq type is not transitional decoding #187

Closed laskoviymishka closed 1 year ago

laskoviymishka commented 1 year ago

Not sure is that a proper way to handle those types:

func TestLSEQ(t *testing.T) {
    v := new(pgtype.Lseg)
    require.NoError(t, v.DecodeText(nil, []byte("[(1,2),(2,3)]")))
    vv, err := pgtype.EncodeValueText(v)
    require.NoError(t, err)
    require.NoError(t, v.DecodeText(nil, []byte(vv.(string))))
}

Maybe it worth to add into lseg.EncodeText extra columns (wrap with [ and ])

jackc commented 1 year ago

This confused me at first because TestLsegTranscode tests encoding and decoding the binary and text formats.

It appears what is happening is the [ and ] are optional to PostgreSQL, but it always normalizes the output to include them.

jack@[local]:5432 pgx_test=# select '(1,2),(2,3)'::lseg;
     lseg
───────────────
 [(1,2),(2,3)]
(1 row)

I've made your suggested change in pgtype and pgx v5.