> On Dec 4, 2014, at 9:36 AM, Ladislav Lenart <[email protected]> wrote: > > Hello. > > The following code crashes: > > # db init... > meta = MetaData() > foo = Table('tmp_foo' meta, > Column('id', Integer, primary_key=True), > prefixes=['TEMPORARY'], > ) > conn = session.connection() > foo.create(conn, checkfirst=True) > foo.create(conn, checkfirst=True) > > > This is because the 'check-first' logic emmits the following SQL: > > SELECT relname > FROM > pg_class c > JOIN pg_namespace n ON n.oid=c.relnamespace > WHERE > n.nspname=CURRENT_SCHEMA() > AND relname='tmp_foo' > > > The culrpit is in a call to CURRENT_SCHEMA() because temporary tables in > postgres reside in a special schema. > > Is there a fix/workaround for this?
issue https://bitbucket.org/zzzeek/sqlalchemy/issue/3264/has_table-in-postgresql-doesnt-work-for has been created and fixed for 1.0. For now, I’d avoid using “checkfirst” for a temporary table. As this is only local to a transaction it should be straightforward just to make sure the code is only calling create() once. If this is unavoidable, then place the call to create() within a conditional that runs the new query: "select relname from pg_class c join pg_namespace n on " "n.oid=c.relnamespace where " "pg_catalog.pg_table_is_visible(c.oid) " "and relname=:name”, PG’s behavior unfortunately allows a non-temporary table to silently overwrite a temporary one, so this change is a significant behavioral change to the checkfirst flag. -- 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/d/optout.
