Thanks, Jeremy. It worked.

On Thursday, February 25, 2021 at 6:59:27 PM UTC+3 Jeremy Evans wrote:

> On Wed, Feb 24, 2021 at 7:24 PM [email protected] <[email protected]> 
> wrote:
>
>> Hi Jeremy,
>>
>> I am bit lost for string_agg in PostgreSQL when converting to Sequel.
>>
>> How can I write this code with Sequel?
>>
>>      SELECT
>>         "f"."id",
>>         "f"."uid",
>>         string_agg(distinct CAST (dirs.uid AS text), ',' order by CAST 
>> (dirs.uid AS text)) as dirs_uids
>>       FROM "paths" as "f"
>>       JOIN dirs ON "f".id = dirs.folder_id
>>       WHERE (paths.user_idx = 1)
>>       GROUP BY "f".id, "f"."uid"
>>       LIMIT 50
>>
>
>  
> DB.from{paths.as(:f)}.
>   select_group{[f[:id], f[:uid]]}.
>   select_append{string_agg(dirs[:uid].cast(String), 
> ',').distinct.order(dirs[:uid].cast(String))}.
>   join(:dirs, :folder_id=>:id).
>   where{{paths[:user_idx]=>1}}.
>   limit(50)
>
> SELECT "f"."id", "f"."uid", string_agg(DISTINCT CAST("dirs"."uid" AS 
> text), ',' ORDER BY CAST("dirs"."uid" AS text))
> FROM "paths" AS "f"
> INNER JOIN "dirs" ON ("dirs"."folder_id" = "f"."id")
> WHERE ("paths"."user_idx" = 1)
> GROUP BY "f"."id", "f"."uid"
> LIMIT 50
>
> 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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sequel-talk/0a8f009b-0e1d-4031-b53f-9c52a3f2295dn%40googlegroups.com.

Reply via email to