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.

I'm trying to keep only the latest event for each entity (entity_type + 
entity_id)

Events table

 id               | uuid                        | not null default 
uuid_generate_v4()
 at               | timestamp without time zone | not null default now()
 entity_type      | text                        | not null
 entity_id        | uuid                        | not null


Thanks

--  
Nicolas Goy
Programmer
http://kuon.goyman.com

-- 
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