On Sun, 13 Jun 2010 13:33:39 +0530, Faheem Mitha <fah...@email.unc.edu> wrote:
> I'm going to assume comment 1 and comment 2 are unrelated. If they > aren't, please correct me. > > As regards 1, I assume you mean try... pass... is a bad idea. I agree, > but there is no > > CREATE LANGUAGE IF EXISTS > > in PostgreSQL, so CREATE LANGUAGE exits with an error if the language > already exists. So, what alternative do you suggest? I guess catching > the exception within pg itself is an option - I've done it in at least > one other case. The advantage with that approach is that one can then > finetune the catching of the exception more precisely. However, I > don't know if this is relevant to what you mean. > > As far as 2, I'm not sure what "transactionalized execution" is. I > tried Googling for this, and came up, for example, with > > http://www.sqlalchemy.org/docs/dbengine.html#using-transactions-with-connection > > but this didn't help me understand what the problem was. If the > problem is that the transaction does not commit immediately, why > should that cause an error? > > I remembered that text() has the autocommit=True option, and tried > using it with create_drop_constraint_if_exists_function, but it didn't > help. [Following up to myself] Adding session.commit() after try: session.execute(create_plpgsql) except: pass makes this work. I'm still not sure what is happening here, but possibly session.execute(create_plpgsql) needs a chance to clean up after itself before another transaction? If that is right, then your two comments were in fact related. :-) I note that setting autocommit=True on create_plpgsql doesn't work, presumably because it errors out, and therefore cannot be committed. Regardless, a expert explanation would be appreciated. Would using something like http://wiki.postgresql.org/wiki/CREATE_OR_REPLACE_LANGUAGE be a reasonable solution to this? Then the try except would not be necessary. Thanks, Faheem. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.