George V. Reilly wrote: > I'm at the MySQL conference. A couple of speakers have recommended > adding SQL comments to queries for debugging; e.g., attributing a > query to a higher-level operation, or that can be parsed by a slave > during replication. > > Is there a way to do this in SQLAlchemy? That is, the generated SQL > has a /* comment */ inserted by my code. >
At the SQL expression layer, you have several ways to include comments in the compiled SQL statement: 1. The "prefixes" parameter to insert(): http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.insert 2. prefix_with() generative method on Insert objects: http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.Insert.prefix_with 3. "prefixes" parameter to select(): http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.select 4. append_prefix() generative method on Select objects: http://www.sqlalchemy.org/docs/reference/sqlalchemy/expressions.html#sqlalchemy.sql.expression.Select.append_prefix e.g. select([table], prefixes=["/* some comment */"]) would compile as "SELECT /* some comment */ column1, column2 FROM table" If you want to apply prefixes by default or at the ORM layer, check out this thread: http://groups.google.com/group/sqlalchemy/browse_thread/thread/a7e05537ae504d61 -Conor -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@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.