Legacy systems =) The database was already in place as this,
unfortunately when I migrated from access to postgres I kept the same
schema as I was under a time crunch to get *something* running.... And
now it bites me in the butt.

The thing is... I cannot do this
``db(db.table.id==3).update(db.table.field=db.table.field+1) ``.

It is not ATOMIC and crashes the application underneath a certain load.

Why does web2py NOT have an autoincrement attribute? Databases are
kinda designed for this thing =)

Massimo, what reasons do you justify for not having one?

--
Thadeus





On Mon, Jun 7, 2010 at 9:56 PM, mr.freeze <nat...@freezable.com> wrote:
> I'm not even going to ask how you got in this situation :) Could you?:
>
> 0) Create a patch to Field for an autoincrement field type
> 1) Create a new table (whopper_temp) on your database with an id field
> that is NOT set to auto-increment (yet)
> 2) Copy all records from the table in question to whopper_temp,
> casting whopper_id to an integer as you go.
> 3) Rename your source table
> 4) Rename whopper_temp to the source tables original name
> 5) Change Field type for whopper_id to your new autoincrement type
>
>
> On Jun 7, 8:29 pm, Thadeus Burgess <thade...@thadeusb.com> wrote:
>> I have a problem.
>>
>> I have this in the database....
>>
>> Field("whopper_id", "string", default=None, unique=True),
>>
>> The thing with whopper_id is it always stores numbers. Said numbers
>> are anywhere from 20000 to 60000.
>>
>> Also upon entering a new entry, I do the following
>>
>> last_whopper_id = db(db.table.id > 0).select(db.table.whopper_id,
>> orderby=~db.table.whopper_id, limit=(0,1)).first().whopper_id
>> db.insert(whopper_id = (int(last_whopper_id) + 1))
>>
>> So I do all this juju just to get the number to autoincrement.
>>
>> The problem is, this structure is bad... first I'm storing integers in
>> a string field, and then manually incrementing them!!!!
>>
>> I get errors like... IntegrityError: duplicate key value violates
>> unique constraint "table_whopper_id_key"... when two requests come in
>> to create a record within miliseconds of each other.
>>
>> Here is where I need some help please.
>>
>> I need to convert this entire field, into an autoincrementing integer
>> performed by the database, however ALL current whopper_ids must stay
>> EXACTLY the same.
>>
>> I don't know how to accomplish this with web2py. I know what I want...
>>
>> Field("whopper_id", "integer", unique=True, autoincrement=True)
>>
>> But how do I convert all existing whopper_ids over and keep them the exact 
>> same?
>>
>> Is this even possible with web2py and the DAL?
>>
>> --
>> Thadeus
>

Reply via email to