nodes.select{|o| [o.members[:id].as(:_id)] + 
[Sequel[:member_integrations][:id]]}.distinct{members[:id]}.from_self.select(:_id).limit(50).count

fails on ERROR:  SELECT DISTINCT ON expressions must match initial ORDER BY 
expressions (Sequel::DatabaseError)

Not sure if i fully understand the idea. When i take these ordered 600 rows 
and i need to limit them, subselect DISTINCT needs to be ordered by 
member_id first, which means that the ordered 600 rows would be limited by 
unordered 50 members.

 

Dne čtvrtek 29. července 2021 v 19:36:18 UTC+2 uživatel Jeremy Evans napsal:

> On Thu, Jul 29, 2021 at 10:21 AM Michal Macejko <[email protected]> 
> wrote:
>
>> nodes.select{members[:id]}.distinct.from_self.limit(50)
>>
>> where nodes are: nodes = 
>> current_account.members_dataset.eager_graph(member_integrations: 
>> [:member_integration_fields])
>>
>> fails on PG::InvalidColumnReference: ERROR:  for SELECT DISTINCT, ORDER 
>> BY expressions must appear in select list
>>
>
> That makes sense.  You need to make sure the subselect that uses DISTINCT 
> selects the expressions you are ordering by, but is only distinct on the 
> member id.  After the from_self, you can just select the id field.
>
> nodes.select{|o| [o.members[:id].as(:_id)] + array_order
> }.distinct{members[:id]}.from_self.select(:_id).limit(50)
>  
> Regarding "plus order in subselect won't be taking into account. subselect 
> (IN) does not respect order of IDs.", that shouldn't matter.  The IN 
> predicate is just to limit the results, the order you specified will still 
> be used to ensure the expected order.
>
> 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/4bdfd5cf-0b30-4a64-8180-b53370e6adddn%40googlegroups.com.

Reply via email to