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/CADGZSScQq40qeedrKrUnEy%2B1FvHwNTSGDgVf%3DmVNa6wStZ2omA%40mail.gmail.com.

Reply via email to