[Chicago] auto incrementing - what options do we have?

DiPierro, Massimo MDiPierro at cs.depaul.edu
Fri Oct 10 18:11:30 CEST 2008


A quick and dirty trick would be to have a normal auto-increment field and, after insert, compute "case" and update the insert.

db.define_table('mytable',SQLField('name'),SQLField('case',default=None,unique))
id=db.mytable.insert(name='value')
db(db.mytable.id==id).update(case=f(id))

where f is your function.

Massimo
________________________________________
From: chicago-bounces+mdipierro=cs.depaul.edu at python.org [chicago-bounces+mdipierro=cs.depaul.edu at python.org] On Behalf Of Lukasz Szybalski [szybalski at gmail.com]
Sent: Friday, October 10, 2008 10:18 AM
To: The Chicago Python Users Group
Subject: Re: [Chicago] auto incrementing - what options do we have?

On Fri, Oct 10, 2008 at 8:58 AM, John-Stockton Irick <irick at uchicago.edu> wrote:
> I'm going to assume that you're talking about mysql.
>
> >From mysql.org
> "
>  To start with an AUTO_INCREMENT value other than 1, you can set that
> value with CREATE TABLE or ALTER TABLE, like this:
>
> mysql> ALTER TABLE tbl AUTO_INCREMENT = 100;
> "
>
> http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html
>
> Hope that helps.


Problem with that is that I want to have more control on case#. So if
this case is from A source the auto increment starts at case# 3000 and
if its from source B auto increment starts with case# 4000.

Lucas
_______________________________________________
Chicago mailing list
Chicago at python.org
http://mail.python.org/mailman/listinfo/chicago


More information about the Chicago mailing list