[SQL] Prevent double entries ... no simple unique index

2012-07-11 Thread Andreas
Hi, I've got a log-table that records events regarding other objects. Those events have a state that shows the progress of further work on this event. They can be open, accepted or rejected. I don't want to be able to insert addition events regarding an object X as long there is an open or

Re: [SQL] Prevent double entries ... no simple unique index

2012-07-11 Thread Andreas Kretschmer
Andreas maps...@gmx.net wrote: Hi, I've got a log-table that records events regarding other objects. Those events have a state that shows the progress of further work on this event. They can be open, accepted or rejected. I don't want to be able to insert addition events regarding an

Re: [SQL] Prevent double entries ... no simple unique index

2012-07-11 Thread Andreas Kretschmer
Andreas Kretschmer akretsch...@spamfence.net wrote: Andreas maps...@gmx.net wrote: Hi, I've got a log-table that records events regarding other objects. Those events have a state that shows the progress of further work on this event. They can be open, accepted or rejected. I

Re: [SQL] Prevent double entries ... no simple unique index

2012-07-11 Thread Rosser Schwarz
On Wed, Jul 11, 2012 at 12:50 AM, Andreas maps...@gmx.net wrote: [...] I can't simply move rejected events in an archive table and keep a unique index on object_id as there are other descriptive tables that reference the event_log.id. Would a multi-column index, unique on (id, state) meet

Re: [SQL] Prevent double entries ... no simple unique index

2012-07-11 Thread Marc Mamin
Or this one: test=*# create unique index on log((case when state = 0 then 0 when state = 1 then 1 else null end)); CREATE INDEX Now you can insert one '0' and one '1' - value - but no more. Hi, A partial index would do the same, but requires less space: create unique index on

Re: [SQL] Prevent double entries ... no simple unique index

2012-07-11 Thread Andreas Kretschmer
Marc Mamin m.ma...@intershop.de wrote: Or this one: test=*# create unique index on log((case when state = 0 then 0 when state = 1 then 1 else null end)); CREATE INDEX Now you can insert one '0' and one '1' - value - but no more. Hi, A partial index would do the same,