-
Notifications
You must be signed in to change notification settings - Fork 56
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
Unable to encode array of composites #65
Comments
There's intentionally no encoders for composite types, because Postgres doesn't provide enough support for them (on the OID) level. Decoders are not a problem, but Encoders are. |
Nikita Volkov <[email protected]> writes:
There's intentionally no encoders for composite types, because Postgres doesn't provide enough support for them (on the OID) level.
What precisely is missing? Yes, you need to know the OID of the
composite you are trying to construct, but it nevertheless should be
possible to represent them.
|
There is no predefined OID for a composite type |
Is there some way of working around this? I have a table which has a column containing an array of text, integer pairs and I'm not sure how to update or insert to that with Hasql. Would I have to build the explicit SQL for the entire command, including the array content? |
That's an option you always have. As for the alternative, I recommend exploring something in the spirit of a solution to multiple values, based on unzipping of arrays. (Please, post back if you find a solution). BTW, some form of support for composite encoding is likely to come in the next major release. |
Thanks a lot for your super fast response! With the help of that link I managed to get it to work, though I'm pushing my boundaries somewhat, and there may be a better way :). Since my composite type only has two fields it's not overly complex. As suggested I split it into two separate arrays of type The relevant part of my schema is:
and my corresponding Hasql code is
The Haskell data types can be found here. |
Works for storing and retrieving all the story data. Dealing with the composite list of dictionary entries is a bit tricky when doing an insert/update and requires a workaround where the entry is unzipped into arrays and then recombined in the SQL and cast to the dict_entry type. See nikita-volkov/hasql#65 for more information.
Yes. Seems like a good solution. Thanks for posting back! |
The encoders supplied in
Hasql.Encoders
are not expressive enough to represent an array of composite values. Specifically,arrayValue
expects aValue
, which isn't a semigroup.The text was updated successfully, but these errors were encountered: