format exception with DDL statements

Issue #1267 resolved
Former user created an issue

Executing a literal DDL statement causes formatting exception:

>>> from sqlalchemy import *
>>> e = create_engine('sqlite://')
>>> DDL("SELECT '%'").execute(e)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python25\lib\site-packages\sqlalchemy-0.5.0rc4-py2.5.egg\sqlalchemy\schema.py", line 1910, in execute
    executable = expression.text(self._expand(schema_item, bind))
  File "c:\python25\lib\site-packages\sqlalchemy-0.5.0rc4-py2.5.egg\sqlalchemy\schema.py", line 1995, in _expand
    return self.statement % self._prepare_context(schema_item, bind)
ValueError: unsupported format character ''' (0x27) at index 9

For some context, I ran into this problem when attempting to create a pl/python function in PG.

Comments (3)

  1. Mike Bayer repo owner

    you need to escape % signs in postgres as in '%%'. we haven't decided yet to automatically perform this escaping in the text() construct but this would be an 0.5 only change.

  2. Log in to comment