On Sep 28, 2011, at 8:32 AM, Chris Withers wrote:

> On 28/09/2011 13:19, Michael Bayer wrote:
>> well the easiest is mytable.drop(engine, checkfirst=True).
>> 
>> The "check" is not within the DropTable construct, which represents just the 
>> actual DROP TABLE statement.    If you were using DropTable directly you'd 
>> call engine.has_table(tablename) first to check for it.
> 
> Hmm, but both mysql and postgres (I suspect others do too, but I haven't 
> checked) have "DROP TABLE IF EXISTS" statements so you don't need to do any 
> checking. That feels like it should be supported by the DropTable construct, 
> what am I missing?

oh, that.  Right you'd need to use @compiles to enhance a new subclass of 
DropTable to do that, as SQLA's compiler doesn't have the "IF EXISTS" feature 
present at the moment (it could be added).

The "E" is how psycopg2 formats the %s -> table.name parameter in your 
statement for certain versions of Postgresql.  I don't know what it actually 
means but if you watch your PG logs you'll see it's used for all bound 
parameters.

> 
> Anyway, in an effort to get this, I tried:
> 
>  File "...model.py",
> line 46, in <module>
>    engine.execute('drop table if exists %s', table.name)
>  File "sqlalchemy/engine/base.py",
> line 2285, in execute
>    return connection.execute(statement, *multiparams, **params)
>  File "sqlalchemy/engine/base.py",
> line 1399, in execute
>    params)
>  File "sqlalchemy/engine/base.py",
> line 1576, in _execute_text
>    statement, parameters
>  File "sqlalchemy/engine/base.py",
> line 1640, in _execute_context
>    context)
>  File "sqlalchemy/engine/base.py",
> line 1633, in _execute_context
>    context)
>  File "sqlalchemy/engine/default.py",
> line 325, in do_execute
>    cursor.execute(statement, parameters)
> sqlalchemy.exc.ProgrammingError: (ProgrammingError) syntax error at or
> near "E'table_name'"
> LINE 1: drop table if exists E'table_name'
> 
> Where's that E coming from?
> 
> cheers,
> 
> Chris
> 
> -- 
> Simplistix - Content Management, Batch Processing & Python Consulting
>            - http://www.simplistix.co.uk

-- 
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.

Reply via email to