On Sat, Apr 24, 2021 at 4:08 AM abhijit <[email protected]> wrote: > Thanks Jeremy. > > The non-window functions version worked seamlessly - > from(:order_details).order(:orderid, :id).select_hash_groups(:orderid, :id > ).each_value do |ids| > i = 0 > ids.each do |id| > from(:order_details).where(id: id).update(position: i+=1) > end > end > > I really wanted to try the version with window functions, since I'm using > Postgres, but I got this error - > undefined local variable or method `row_number' > > I had tried this (with some changes to the code you gave). I'm sure I'm > not writing the function correctly. > from(:new_table).insert( > [ > :id, > :orderid, > :position > ], > from(:orderdetails).select([ > :id, > :orderid, > row_number.function.order(:id).partition(:orderid) > ]) {} > ) >
This wouldn't work, because `row_number` needs to be called inside the block passed to select.. > I had also tried - > Sequel.function(:row_number) .order(:id).partition(:orderid) > This should work, except that I missed one thing. You need to call over with the :order and :partition options, instead of separate order and partition methods: Sequel.function(:row_number).over(order: :id, partition: :orderid) 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/CADGZSSdHgM7GNK38%3DipqWuzCf0px1NLOF--xghQ4%3DGmXTMr3sA%40mail.gmail.com.
