pgtype icon indicating copy to clipboard operation
pgtype copied to clipboard

slice of typed strings

Open PaulForgey opened this issue 6 years ago • 1 comments

given the type type MyString string and an object of

struct {
  Thing MyString
  Things []MyString
}

Thing will scan fine, as there's a conversion from *string to *MyString. Things will not. Value panics because it cannot come up with a conversion from *[]string to *[]MyString

PaulForgey avatar Sep 04 '20 06:09 PaulForgey

*MyString works because pgtype uses reflection to determine the underlying type is a *string. However, the underlying type of []MyString is not []string. This makes automagically handling it much more difficult.

This could be made to work with sufficient reflection. However, the would be a definite performance cost to doing so. I believe each element would need to go through the entire reflection process individually.

I'm not opposed to this feature, but an implementation would need to meet two conditions.

  1. Not introduce an undue amount of complexity into the code base.
  2. Have benchmarks that show the performance cost is acceptable.

jackc avatar Sep 04 '20 14:09 jackc