[Haskell-cafe] Multicolumn aggregate in Beam

Daneel Yaitskov dyaitskov at gmail.com
Tue Jun 6 16:30:00 UTC 2023


Hi,

I am using beam library in my project and trying to express a query with a
several aggregating subqueries:

select
  (select * from t order by ts desc limit 1),
  (select * from t order by ts asc limit 1),  (select count(*) from t) as nnn

 I figured out how to do multiple columns:
userDataTableDigestQ :: UserTable -> SqlSelect
  Postgres (UserDataTable, UserDataTable)
userDataTableDigestQ ut = select ag
  where
    al = all_ (userDataTableRef $ usertableName ut)
    ag = subselect_ $ aggregate_
      (BF.bimap group_ group_)
      ((,)
        <$> limit_ 1 (orderBy_ (asc_ . userdatatableTs) al)
        <*> limit_ 1 (orderBy_ (desc_ . userdatatableTs) al))

but mixing group_ and count_ produces a very long type error

Is there other sql-backend agnostic Haskell library which could express the
query above?

-- 

Best regards,
Daniil Iaitskov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20230606/f76c4673/attachment.html>


More information about the Haskell-Cafe mailing list