title: How do you create a table with Sqlalchemy within a transaction in Postgres?
body: <p>I'm using Sqlalchemy in a multitenant Flask application and need to create tables on the fly when a new tenant is added. I've been using Table.create to create individual tables within a new Postgres schema (along with search_path modifications) and this works quite well.</p>
  
  <p>The limitation I've found is that the Table.create method blocks if there is anything pending in the current transaction. I have to commit the transaction right before the .create call or it will block. It doesn't appear to be blocked in Sqlalchemy because you can't Ctrl-C it. You have to kill the process. So, I'm assuming it's something further down in Postgres.</p>
  
  <p>I've read in other answers that CREATE TABLE is transactional and can be rolled back, so I'm presuming this should be working. I've tried starting a new transaction with the current engine and using that for the table create (vs. the current Flask one) but that hasn't helped either.</p>
  
  <p>Does anybody know how to get this to work without an early commit (and risking partial dangling data)?</p>
  
  <p>This is Python 2.7, Postgres 9.1 and Sqlalchemy 0.8.0b2.</p>