On Jul 19, 2014, at 3:38 AM, Ofir Herzas <herz...@gmail.com> wrote:

> I have a table with the following column:
> 
> id = sa.Column(sa.Integer, sa.Sequence('id_seq'), primary_key=True, 
> nullable=False)
> Usually, I have no problems inserting data, but every time I insert rows with 
> specific id, it causes problems with Oracle since the sequence is not 
> modified accordingly.
> 
> For example, assuming that the table is new and the sequence starts at 1, if 
> I insert a row specifying id=2, the sequence doesn't change which will cause 
> the next insert to fail.
> 
> I do understand that Oracle does not support auto increment but what is the 
> proper way of handling this under sqlalchemy? Do I need to manually change 
> the sequence after such insert statement? can I bind to an event or use any 
> other magic to make it work like other dialects? (choose max(id)+1)
> 
> 


the case where you have a sequence used for a table and at the same time you 
have the need to insert rows with specific identifiers as a normal matter of 
course (as opposed to when you need to do a bulk insert as part of database 
maintenance) is an unusual one.   Most database folks would ask why that's the 
use case you have.    Surrogate primary keys are not supposed to be meaningful, 
you normally would just let the sequence handle creation of new values 100% of 
the time.    Because they increment atomically, you never have to worry about 
two primary  key identifiers conflicting.   If you're working around that then 
you can't be assured of integrity violations within concurrent scenarios.

Short answer yes if you are inserting values directly then you need to update 
the sequence manually, on oracle i think it might be ALTER SEQUENCE or 
something like that.   It's not the kind of thing that would scale, though.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to