ammar azif wrote:
> 
> Hi,
> 
> The code that I am working on deletes rows from table A that are
> based on a certain query and then recreates these rows based on
> entries supplied by a csv file. Table A is referenced by table B. My
> question is, how does sql alchemy manage inserts and deletes in a
> transaction and it what order are they done? It seems that deletes
> are done after inserts because I am getting unique constraint errors,
> although the rows are deleted before inserts are done. If my
> assumption is correct, how do I change this behaviour in SQLAlchemy.
> I do not want to add unique deferrable constraint into table A
> because its unique constraint key is being referred by table B, this
> is a limitation of postgres.
> 
> Appreciate your feedback

I assume you are using the ORM. (If you are using the low-level API, SQL
statements are executed explicitly via something like
connection.execute())

The ORM executes statements when you call session.flush(). If you call
that after deleting your rows, you should be safe to insert new ones
with the same IDs afterwards.

SQLAlchemy does detect dependencies between rows, so for example it
would know to insert rows into Table A before any rows in Table B that
reference them. However, I don't think it necessarily performs deletions
before insertions.

Simon

-- 
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 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to