On Fri, Nov 18, 2016 at 11:43 AM, Santosh Sharma <chitr.praya...@gmail.com> wrote: > I am using SQLAlchemy and postgres database. > > I want to do "Delete and Insert operation" on the table in a single > transaction without using orm. > > Say > table User > Column | Type | Modifiers > --------+-------------------+--------------------------------------------------- > id | integer | not null default > nextval('test_id_seq'::regclass) > name | character varying | > > > All users from table are retrieved and displayed at small time > interval.(2 secs) > > > say u1,u2,u3 are current users in DB. > > > Updated user list is u3,u4,u5. > > Now i have to delete [u1,u2 ] & add [u4,u5]. This deletion and addition of > users should be in single transaction so that > users retrieved/displayed from table are either [u1,u2,u3] or [u3,u4,u5] . > And to avoid retrieval of transitional list of users say [ u1 ] (after > deletion). > > In the similar steps it is required to do bulk deletion and bulk addition in > a single transaction. >
This section of the docs deals with transactions in SQLAlchemy Core: http://docs.sqlalchemy.org/en/latest/core/connections.html#using-transactions You can execute as many statements as you like between starting and committing the transaction. Hope that helps, Simon -- SQLAlchemy - The Python SQL Toolkit and Object Relational Mapper http://www.sqlalchemy.org/ To post example code, please provide an MCVE: Minimal, Complete, and Verifiable Example. See http://stackoverflow.com/help/mcve for a full description. --- 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 https://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/d/optout.