Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EnumArray does not implement ValueTranscoder #108

Open
drewthor opened this issue May 31, 2021 · 3 comments
Open

EnumArray does not implement ValueTranscoder #108

drewthor opened this issue May 31, 2021 · 3 comments

Comments

@drewthor
Copy link

Not sure if this is on purpose or was just an oversight (if it is purpose please feel free to close this), but EnumArray does not implement ValueTranscoder so users must implement their own custom type with func's EncodeText and DecodeText utilizing EnumArray::DecodeText and EnumArray::EncodeText under the hood. This makes it much more difficult to do binary encoding/decoding (user's must fully implement everything for their custom types) or register data types in pgx simply using a line like:
conn.ConnInfo().RegisterDataType(pgtype.DataType{Value: pgtype.NewArrayType("pg_enum_typname", 1234, func() pgtype.ValueTranscoder { return &pgtype.EnumArray{} }), Name: "pg_enum_typname", OID: oid})

@jackc
Copy link
Owner

jackc commented Jun 12, 2021

I don't remember why EnumArray doesn't implement the binary format because the binary format for an array requires knowing the OID of the element.

I think if you want to register an enum array type you would use NewArrayType, but with GenericText as the element. You don't need an array of arrays.

@drewthor
Copy link
Author

Ahh, that makes sense. So the ValueTranscoder is meant to operate on a singular element of the array vs the entire array. Unfortunately it looks like GenericText can't be used directly as a ValueTranscoder as it also doesn't implement the binary format.

@jackc
Copy link
Owner

jackc commented Jun 19, 2021

Unfortunately it looks like GenericText can't be used directly as a ValueTranscoder as it also doesn't implement the binary format.

Ah, true. Hmmm, the regular Text type does implement the binary format. Could try that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants