Hi!
If I create DDL like this with %:
event.listen(db.metadata, 'after_create', DDL(
"""
CREATE OR REPLACE FUNCTION test_func() RETURNS void AS $$
DECLARE
max_user_id INTEGER;
BEGIN
SELECT INTO max_user_id MAX("id") FROM "user";
RAISE INFO 'max_user_id: (%)', max_user_id;
END;
$$ LANGUAGE plpgsql;
"""
))
and in python shell call db.create_all() for create tables I got
exception:
----> 1 db.create_all()
/usr/lib/python2.7/site-packages/flaskext/sqlalchemy.pyc in
create_all(self, bind, app)
793 Parameters were added
794 """
--> 795 self._execute_for_all_tables(app, bind, 'create_all')
796
797 def drop_all(self, bind='__all__', app=None):
/usr/lib/python2.7/site-packages/flaskext/sqlalchemy.pyc in
_execute_for_all_tables(self, app, bind, operation)
785 tables = self.get_tables_for_bind(bind)
786 op = getattr(self.Model.metadata, operation)
--> 787 op(bind=self.get_engine(app, bind), tables=tables)
788
789 def create_all(self, bind='__all__', app=None):
/usr/lib/python2.7/site-packages/sqlalchemy/schema.pyc in
create_all(self, bind, tables, checkfirst)
2513 self,
2514 checkfirst=checkfirst,
-> 2515 tables=tables)
2516
2517 def drop_all(self, bind=None, tables=None,
checkfirst=True):
/usr/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in
_run_visitor(self, visitorcallable, element, connection, **kwargs)
2232 conn = connection
2233 try:
-> 2234 conn._run_visitor(visitorcallable, element,
**kwargs)
2235 finally:
2236 if connection is None:
/usr/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in
_run_visitor(self, visitorcallable, element, **kwargs)
1902 def _run_visitor(self, visitorcallable, element,
**kwargs):
1903 visitorcallable(self.dialect, self,
-> 1904 **kwargs).traverse_single(element)
1905
1906
/usr/lib/python2.7/site-packages/sqlalchemy/sql/visitors.pyc in
traverse_single(self, obj, **kw)
84 meth = getattr(v, "visit_%s" % obj.__visit_name__,
None)
85 if meth:
---> 86 return meth(obj, **kw)
87
88 def iterate(self, obj):
/usr/lib/python2.7/site-packages/sqlalchemy/engine/ddl.pyc in
visit_metadata(self, metadata)
70 tables=collection,
71
checkfirst=self.checkfirst,
---> 72 _ddl_runner=self)
73
74 def visit_table(self, table, create_ok=False):
/usr/lib/python2.7/site-packages/sqlalchemy/event.pyc in
__call__(self, *args, **kw)
272 fn(*args, **kw)
273 for fn in self.listeners:
--> 274 fn(*args, **kw)
275
276 # I'm not entirely thrilled about the overhead here,
/usr/lib/python2.7/site-packages/sqlalchemy/schema.pyc in
__call__(self, target, bind, **kw)
2823
2824 if self._should_execute(target, bind, **kw):
-> 2825 return bind.execute(self.against(target))
2826
2827 def _check_ddl_on(self, on):
/usr/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in
execute(self, object, *multiparams, **params)
1403 object,
1404 multiparams,
-> 1405 params)
1406 else:
1407 raise exc.InvalidRequestError(
/usr/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in
_execute_ddl(self, ddl, multiparams, params)
1488 dialect = self.dialect
1489
-> 1490 compiled = ddl.compile(dialect=dialect)
1491 ret = self._execute_context(
1492 dialect,
/usr/lib/python2.7/site-packages/sqlalchemy/sql/expression.pyc in
compile(self, bind, dialect, **kw)
1720 else:
1721 dialect = default.DefaultDialect()
-> 1722 return self._compiler(dialect, bind=bind, **kw)
1723
1724 def _compiler(self, dialect, **kw):
/usr/lib/python2.7/site-packages/sqlalchemy/schema.pyc in
_compiler(self, dialect, **kw)
2850 Dialect."""
2851
-> 2852 return dialect.ddl_compiler(dialect, self, **kw)
2853
2854 class DDL(DDLElement):
/usr/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in
__init__(self, dialect, statement, bind)
697 self.statement = statement
698 self.can_execute = statement.supports_execution
--> 699 self.string = self.process(self.statement)
700
701 @util.deprecated("0.7", ":class:`.Compiled` objects now
compile "
/usr/lib/python2.7/site-packages/sqlalchemy/engine/base.pyc in
process(self, obj, **kwargs)
716
717 def process(self, obj, **kwargs):
--> 718 return obj._compiler_dispatch(self, **kwargs)
719
720 def __str__(self):
/usr/lib/python2.7/site-packages/sqlalchemy/sql/visitors.pyc in
_compiler_dispatch(self, visitor, **kw)
57 getter = operator.attrgetter("visit_%s" %
visit_name)
58 def _compiler_dispatch(self, visitor, **kw):
---> 59 return getter(visitor)(self, **kw)
60 else:
61 def _compiler_dispatch(self, visitor, **kw):
/usr/lib/python2.7/site-packages/sqlalchemy/sql/compiler.pyc in
visit_ddl(self, ddl, **kwargs)
1345 context.setdefault('fullname',
preparer.format_table(ddl.target))
1346
-> 1347 return
self.sql_compiler.post_process_text(ddl.statement % context)
1348
1349 def visit_create_schema(self, create):
ValueError: unsupported format character ')' (0x29) at index 192
How I can fix this?
Thanks!
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.