Aha! Got it.

Thank you very much!

Best

On Tue, 7 Apr 2020, 21:17 Jeremy Evans, <jeremyeva...@gmail.com> wrote:

> On Tuesday, April 7, 2020 at 11:11:59 AM UTC-7, Marcelo wrote:
>>
>> Hello,
>>
>> I'm trying to produce this query with Sequel, that would then run on
>> PostgreSQL:
>> SELECT o.id, coalesce(cg.price, o.price) price
>> FROM offers o
>> LEFT JOIN country_groups cg ON cg.offer_id = o.id AND cg.country_codes @>
>> '{"US"}'
>>
>>
> You can pass a block to left_join:
>
> DB.from{offers.as(:o)}.
>   select{[o[:id], coalesce(cg[:price], o[:price]).as(:price)]}.
>   left_join(Sequel[:country_groups].as(:cg),
> :offer_id=>:id){Sequel[:cg][:country_codes].pg_array.contains(["US"])}
>
> SQL:
>
> SELECT "o"."id", coalesce("cg"."price", "o"."price") AS "price"
> FROM "offers" AS "o"
> LEFT JOIN "country_groups" AS "cg" ON (("cg"."offer_id" = "o"."id") AND
> ("cg"."country_codes" @> ARRAY['US']))
>
> Thanks,
> Jeremy
>
> --
> 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 sequel-talk+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/sequel-talk/bf8f503c-d05b-4830-a8ce-b5d4f1ab87fa%40googlegroups.com
> <https://groups.google.com/d/msgid/sequel-talk/bf8f503c-d05b-4830-a8ce-b5d4f1ab87fa%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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 sequel-talk+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/CANtavQ7dSv%2BMMpyS4wtOy1gfvQv5b%3DmrWV8UmKcgAQQ%2BVRK0gA%40mail.gmail.com.

Reply via email to