>-----Original Message----- >From: Tom Lane [mailto:tgl@xxxxxxxxxxxxx] >Sent: donderdag 22 februari 2007 17:16 >To: Joris Dobbelsteen >Cc: pgsql-general@xxxxxxxxxxxxxx >Subject: Re: [GENERAL] Guarenteeing ordering constraints > >"Joris Dobbelsteen" <Joris@xxxxxxxxxxxxxxxxxxxxx> writes: >> I have some trouble guarenteeing that an ordering constraint is >> enforced on the database. On the table ordering (see below) >I want to >> enforce that for every tuple t, all tuples u where u.position < >> t.position this implies u.cumvalue <= t.cumvalue. > >I can't think of any reasonable way to enforce that in SQL. >Perhaps you should consider restructuring your tables in such >a way that this behavior emerges from a constraint that is >enforceable --- maybe the cumulative values should be a >(materialized?) view on an underlying table that contains >individual observations. Mmm, it seems that I'm beyond the boundaries. I seem to have the habit of wanting just a little more than is possible. Nevertheless this seemed simple enough... Of course there is no way to force the trigger to read all commited rows and be waiting on the (possibly) required uncommitted ones? This may get triggers closer to the constraints (like unqiue indexes and foreign keys). Seems triggers are more for business intelligence... Thinking over the idea, I strongly believe restructing is going to cause more trouble than anything else. Beyond that, there are now enough constraints that I'm sure I cannot enforce anyways. That is, I cannot even think about a good way to do it. The current triggers will prevent bad things most of the time, but not always. At this point that seems good enough for practical situations. Example: You have a printer, that's of some kind of model. With the model you define what cartridges (colors) you can put in. You can now replace a cartridge on a printer. Of course you want to enforce that the color of the cartridge you replace is valid. Same problem, and I'm quite sure I cannot enforce it. I believe something fundamental should change to ensure we can enforce these constraints. At least, that would be a lot nicer. - Joris