I've achieved similar query by this:
.select(to.get_text('email').as(:email), to.get_text('name').as(:name))
.cross_join(Sequel.function(:jsonb_array_elements, :receiver).lateral)
.order(Sequel.desc(to.get_text('email')), Sequel.desc(:id))
.distinct(to.get_text('email'))
However, i couldn't properly write this line:
CROSS JOIN LATERAL *jsonb_array_elements**(sr.receiver) x (e)*
On Friday, May 24, 2019 at 12:55:01 PM UTC+3, xura wrote:
>
> Hi,
>
> Is it possible to write this query with Sequel?
>
> SELECT DISTINCT ON (x.e->>'email')
> x.e->>'email' as email,
> x.e->>'name' as name
> FROM messages sr
> CROSS JOIN LATERAL jsonb_array_elements(sr.receiver) x (e)
> ORDER BY x.e->>'email', id desc
>
> Or I use *with_sql?*
>
> Thanks!
>
--
You received this message because you are subscribed to the Google Groups
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
To view this discussion on the web visit
https://groups.google.com/d/msgid/sequel-talk/dc6793c6-1398-41f9-a37f-4c0a8871104e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.