I use such code to generate raw SQL from SQLA-queries:

def compile_statement(statement):
    comp = statement.compile(dialect=postgresql.dialect())
    params = {}
    for k, v in comp.params.items():
        if isinstance(v, unicode):
            v = v.encode(cls.encoding)
        params[k] = adapt(v)
    return (comp.string.encode(cls.encoding) % params).decode(cls.encoding)


def compile_query(query):
    return cls.compile_statement(query.statement)

>>> print(compile_query(Foo.query.filter(Foo.bar == 
>>> 'zoo').with_entities(Foo.bar))
SELECT foos.bar as foos_bar
FROM foos
WHERE foos.bar = 'zoo'


Is there any way to generate raw SQL insert statement, generated by this 
code?
Foo(bar='zoo').save()

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to