pgtype icon indicating copy to clipboard operation
pgtype copied to clipboard

Set a ValueTranscoder from the same type errors

Open jschaf opened this issue 3 years ago • 1 comments

I'm trying to generate code to handle a composite type that contains a pgtype.Interval: https://github.com/jschaf/pggen/issues/49. The main issue seems to be that pgtype doesn't support Set with the same type. This test case shows the error:

func TestPgtype_Interval(t *testing.T) {
	v1 := pgtype.Interval{Days: 2, Status: pgtype.Present}
	v2 := pgtype.Interval{Days: 2, Status: pgtype.Present}
	err := v1.Set(v2)
	require.NoError(t, err) // Received unexpected error: cannot convert {0 2 0 2} to Interval
}

Two questions:

  1. Is it reasonable to support Set from the same type? Get returns the same type so it'd have a nice symmetry.
  2. Would you take a PR for this feature?

jschaf avatar May 23 '22 03:05 jschaf

Seems reasonable.

jackc avatar May 23 '22 22:05 jackc