On Feb 16, 2011, at 10:22 AM, Landreville wrote: > Hi, > I am trying to set a session variable (call a function with a value) > in postgres at the beginning of every session that SQLAlchemy starts. > I'm using the session variable to specify the currently logged in user > for an auditing system (just a trigger on a couple tables). I have > tried the before_commit ORM event, but it will set the variable after > the other commands so the trigger does not pick it up. I also tried > the before_flush event, but it seems to have a simlar problem -- it > doesn't always set the variable at the beginning of the session. > > Is there a way to run a command at the beginning of every session, > before anything else is run?
SessionExtension has an after_begin() hook for this purpose. > > Also, in these cases should I be using Session.execute or > Session.connection.execute()? Session.execute() is a shorthand version of Session.connection.execute(). The former also coerces plain textual statements to sqlalchemy.sql.expression.text() so that a single string format may be passed. -- 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.