On Wednesday, July 9, 2014 7:07:43 AM UTC-7, Nicolas Goy wrote:
>
> I have been trying to do the following SQL with sequel (PostgreSQL 9.3): 
>
> delete from events evt 
> using ( 
>   select id, row_number() over (partition by (entity_type, entity_id) 
> order by at desc) as rn from events 
> ) evt2 
> where 
> evt2.rn > 1 
> and 
> evt2.id = evt.id 
>
>
> But I can't figure how to generate it. 
>

DB[:events___evt, 
DB[:events].select(:id){row_number{}.over(:partition=>[:entity_type, 
:entity_id], 
:order=>Sequel.desc(:at)).as(:rn)}.as(:evt2)].where(:evt2__id=>:evt__id){evt2__rn
 
> 1}

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 http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to