On Thu, Dec 05, 2013 at 10:25:46AM -0800, Jonathan Vanasco wrote: > > i'm looking at moving some raw sql in twisted to SqlAlchemy and have a > question. > > I have a multi-threaded twisted daemon that tends to generate a lot of race > conditions on a few tables that are frequently hit. > > I get integrity errors from something like this : > > domain = """SELECT * FROM domains WHERE ...."" > if not domain : > domain = """INSERT INTO domain VALUES .... > > the fix was : > > domain = """SELECT * FROM domains WHERE ....""" > if not domain : > try: > savepoint = db.savepoint() > """INSERT INTO domain VALUES ....""" > except psycopg2.IntegrityError : > savepoint,release() > domain = """SELECT * FROM domains WHERE ....""
A maybe better way would be http://www.postgresql.org/docs/current/static/plpgsql-control-structures.html#PLPGSQL-UPSERT-EXAMPLE > > is there a way to catch an integrity error like this with SqlAlchemy ? > > i'm trying to get away from directly using psycopg2, it's getting too > annoying to maintain raw sql. > > -- > 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 [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/sqlalchemy. > For more options, visit https://groups.google.com/groups/opt_out. -- No trees were killed in the creation of this message. However, many electrons were terribly inconvenienced. -- 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/sqlalchemy. For more options, visit https://groups.google.com/groups/opt_out.
