pgx: possible bug with enum handling

I read #287, could it be it broke something with enum handling?

I get a panic when trying to insert a custom type (with string being the underlying type):

*pgtype.GenericText is not pgtype.BinaryEncoder: missing method EncodeBinary

The panic occurs on line values.go:166 (function encodePreparedStatementArgument):

argBuf, err := value.(pgtype.BinaryEncoder).EncodeBinary(ci, buf)

Any idea?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 17 (15 by maintainers)

Most upvoted comments

Patch looked good to me. I merged it in. As far as enum and binary, I don’t think that would be possible without inspecting what are the underlying integer values in the PG database and generating a PG type from that. That’d be a bit more magic than I’m comfortable with.

@bobheadxi There are a few more changes I want to get in before the next minor release. Probably be finished within a couple weeks.

yeah i didn’t either, changed the default case to an error:

		var argBuf []byte
		switch valueEncoder := value.(type) {
		case pgtype.BinaryEncoder:
			argBuf, err = valueEncoder.EncodeBinary(ci, buf)
		case pgtype.TextEncoder:
			argBuf, err = valueEncoder.EncodeText(ci, buf)
		default:
			return nil, fmt.Errorf("invalid encode type %v", valueEncoder)
		}