-
Notifications
You must be signed in to change notification settings - Fork 115
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
How to fold a query into an SqlArray if it contains multiple fields? #558
Comments
Opaleye doesn't support SQL-level tuples (anonymous records) yet, so you can't do quite that, but you can aggregate into two separate arrays and then |
That seems simple enough, though would the type of |
Hmm, yes, but that seems like a bug in arrayAgg_ :: Aggregator (F.Field_ n a) (F.Field (T.SqlArray_ n a))
arrayAgg_ = Opaleye.Internal.Aggregate.makeAggr HPQ.AggrArr and let me know if that works OK? If so I can add it to Opaleye. |
Should I need a |
Thanks for reporting all of these omissions regarding nullable fields. It looks like I made a lot of oversights when converting from You are correct that the instance has been incorrectly omitted. Please try adding it back locally with instance (Typeable b, DefaultFromField a b) =>
DefaultFromField (T.SqlArray_ Nullable a) [Maybe b] where
defaultFromField = fromFieldArrayNullable defaultFromField I will add this instance in a bugfix release too. |
This should have been added when we did the Column -> Field conversion Addresses #558 (comment)
This should have been added when we did the Column -> Field conversion Addresses #558 (comment)
This should have been added when we did the Column -> Field conversion Addresses #558 (comment)
The instance issue should be fixed in https://hackage.haskell.org/package/opaleye-0.9.4.0. Let me know if this doesn't solve the problem for you. |
So I tried using |
Nice! I should add |
OK, |
So if this can be accomplished with the product-profunctors interface instead of lenses it might be worthwhile adding an example to the documentation for
where It still makes me a touch nervous to trust postgresql to share the work duplicated in each aggregation, but I don't think there's any way to avoid that with the zipping idiom regardless of whether it's abstracted like this or not. I don't know if that concern is really warranted given how thoroughly DBMSes are optimized. |
I'm trying to return some data from my database representing a one-to-many relation, and am trying to do it in a single query, but don't see how to accomplish it. There is
arrayAgg :: Aggregator (Field a) (Field (SqlArray a))
, but the type seems to restrict me from returning more than a single field in each element of the array. In Postgresql you can do things likeselect array_agg((x,y)) from sometable;
, so I don't think this should be a limitation, but I'm not sure if the more first-class-ish tuples that can be put into arrays are actually supported. Unless there's some combinator that can do things likeField_ n a -> Field_ m b -> Field (Field_ n a, Field_ m b)
I'm not sure how I might do this.For the moment I just have a for loop with a separate query for every element retrieved from the first table, but this is obviously not ideal if there's a way around it. Ultimately I want the returned type from the query to be something like
[(a, [b])]
.The text was updated successfully, but these errors were encountered: