My comments inlined.

2007/5/6, Geert Bevin <[EMAIL PROTECTED]>:
I don't think that this is something that's even supported by the
database wrt sequences. In any way, doing a:
SELECT max(id) FROM tablename;

Isn't that much of a deal, is it?

If your code dosn't care about dirty reads, then it's perfectly fine.



On 05 May 2007, at 19:43, David HM Spector wrote:

> Here's an interesting problem... in a perfect world, the ID
> sequence for
> a primary key in a table should increase (usually) monotonically, and
> always be under the control of the DB.

Uniqueness is the only guarentee normally provided by the DB for
primary keys. Primary keys aren't always numbers.

> However, if for whatever
> reason,
> you have to edit a table or reset the table without manually resetting
> the sequence, you will most likely eventually get duplicate key errors
> when you try to insert rows into your table.  Coding around this by
> catching the duplicate key error is problematic because you don't know
> what the current highest id in the table actually is..
>
> Right now you can use SequenceValue() to find out the current and
> presumed-next value in the sequence, but a new HIGHEST_USED capability
> for this method might be useful for being able to reset a table
> sequence
> at runtime...
>
> (I realize this is sort of asking for forgiveness for tampering
> with the
> DB .. but it seems like a logical bit of defensive programming, rather
> than have to drop tables or write code to re-sequence existing tables
> which could have untold numbers of side-effects.)
>
> thoughts..?

The only reason that I can think of that would warrent a tampering
with the sequencing of a tables PK, is that the primary key has
semantic value. However, if it has semantic value, why would you then
want the DB to generate the value upon inserts?
In my world, you either have non-semantic PKs, and then let the DB set
it's value, or you have semantic PKs and then let the application set
it's value based on some business logic.
That way, you would (hopefully) never have a need for knowing what ID
the DB is going to pick next.

>
> David
>
> --
> ----------------------------------------------------------------------
> ----------
> David HM Spector
> [EMAIL PROTECTED]
> voice: +1 631.261.5013                                 http://
> www.zeitgeist.com/
>
>  "New and stirring things are belittled because if they are not
> belittled,
>  the humiliating question arises, 'Why then are you not taking part
> in them?'"
>                                                                   --
> H. G. Wells
>
>
> _______________________________________________
> Rife-users mailing list
> Rife-users@uwyn.com
> http://lists.uwyn.com/mailman/listinfo/rife-users
>

--
Geert Bevin
Terracotta - http://www.terracotta.org
Uwyn "Use what you need" - http://uwyn.com
RIFE Java application framework - http://rifers.org
Music and words - http://gbevin.com


_______________________________________________
Rife-users mailing list
Rife-users@uwyn.com
http://lists.uwyn.com/mailman/listinfo/rife-users



--
Venlig hilsen / Kind regards,
Christian Vest Hansen.
_______________________________________________
Rife-users mailing list
Rife-users@uwyn.com
http://lists.uwyn.com/mailman/listinfo/rife-users

Reply via email to