[ale] Getting the next index of a table in mysql

Chris Fowler cfowler at outpostsentinel.com
Thu Jun 9 09:03:10 EDT 2005


I've attached a perl program where I hacked out a way to get the next
logical entry.  This program does not do the insert yet.


On Thu, 2005-06-09 at 08:25 -0400, Michael B. Trausch wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: RIPEMD160
> 
> James Sumners wrote:
> > It would be better to do the INSERT first and then get the number.
> > That way you can be sure that it is the correct number. But, "SELECT
> > pri_key_num + 1 FROM table ORDER BY pri_key_num DESC LIMIT 1;"
> > 
> 
> Also, note that this will only work if there are zero deletions from the
> table in question.  If you make a deletion in a table, and you don't
> re-order the table by pri_key_num, then eventually you will find that
> you're performing INSERTs that aren't any longer using the correct row
> ids, and you'll have gaps in numbering if you use any other method to
> add a number.
> 
> Checking the new Row ID after an insert is the only real way to go about it.
> 
> 	- Mike
> 
> - --
> Michael B. Trausch                                     fd0man at gmail.com
> Web: http://fd0man.theunixplace.com/        Jabber: mtrausch at jabber.com
> Phone: +1-(678)-522-7934                  FAX (US Only): 1-866-806-4647
> =======================================================================
>   Do you have PGP or GPG?  Key at pgp.mit.edu, Please Encrypt E-Mail!
> 
> 
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.1 (GNU/Linux)
> Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
> 
> iD8DBQFCqDVWPXInbkqM7nwRA8CDAJ0VdF6T7s7ll93/wKScKIqoxiXGdwCeKgeH
> /eiTjnrIkApxNRBfTsmRGPI=
> =xfuC
> -----END PGP SIGNATURE-----
> _______________________________________________
> Ale mailing list
> Ale at ale.org
> http://www.ale.org/mailman/listinfo/ale
-------------- next part --------------
A non-text attachment was scrubbed...
Name: serial.pl
Type: application/x-perl
Size: 1843 bytes
Desc: not available




More information about the Ale mailing list