I fixed it with 
Sequel.lit('(array_agg(grades.section_id))[1]')

but maybe it can be done in a more beautiful way


пятница, 16 ноября 2018 г., 9:13:59 UTC+10 пользователь Artur Trofimov 
написал:
>
> Hello, Jeremy!
>
> How it should be used in this case?
>
> I need
> (array_agg(grades.section_id)) [ 1 ] AS section_id
>
> But
> Sequel.function(:array_agg, :grades__section_id).sql_subscript(1).as(:
> section_id)
>
> Produces 
> array_agg(grades.section_id) [ 1 ] AS section_id
>
> which catch 
> syntax error at or near "["
>
> How to add brackets around array_agg() ?
>
> четверг, 27 сентября 2018 г., 3:00:07 UTC+10 пользователь Jeremy Evans 
> написал:
>>
>> On Wednesday, September 26, 2018 at 8:37:50 AM UTC-7, Harlow wrote:
>>>
>>> i'm trying to select the first element from an array_agg function:
>>> https://www.postgresql.org/docs/9.5/static/functions-aggregate.html
>>>
>>> The issue is i'm having trouble figuring out where to put the `[1]` when 
>>> using Sequel
>>>
>>> For example i'd like the first value of the array:
>>>
>>> array_agg(ids)[1] as id
>>>
>>>
>>> However in in Sequel I'm not sure how to get the first element:
>>>
>>> Sequel.function(:array_agg, ids).as(:id) # => this is array
>>>
>>>
>>> Is there a Sequel syntax for `[1]`?
>>>
>>
>> Sequel.function(:array_agg, ids).sql_subscript(1).as(:id)
>>
>> 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 post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to