orm-wise, u can probably use MapperExtension.before_insert(), and set up the value there. but this is worst as speed, synchronisation etc.
At lower level (SQL) - wait for other answers. There were some threads about using sql-functions for primary keys, see last week or so. On Tuesday 24 April 2007 06:08:29 [EMAIL PROTECTED] wrote: > Hi everyone, > > I have a product table which has a product_id field as the primary > key. I'd like to have the value of this field be generated from two > sequences with different number range depending on the content of > the product_type field. E.g., when product_type == 1, product_id > will be generated between 1000 and 8999, and when product_type == > 2, product_id will be generated between 9000 and 9999. > > In the database, I can simply define a before insert trigger, and > get the next value from the 2 sequences depending on the value of > product_type, since the trigger function has access to the whole > record to be inserted. > > In SQLAlchemy however, I can find a way to define such a table. > Because product_id is the primary key column, I can't use a > database trigger with PassiveDefault since it will be pre-executed > anyway. It seems that I shall use a pre-executed default function > to fetch the appropriate sequence value, but I couldn't find a way > to access the product_type field from within the default function. > > How do I access other table columns from the default function? If > it is not possible, is there a work around for my situation? > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---