On Nov 4, 2011, at 3:19 PM, Roger Hoover wrote: > Hi, > > I'm trying to use the sqlalchemy compiler to generate insert statements that > I can feed myself to MySQLdb. With a sqlalchemy table definition, I'm able > to get a nice SQL statement using the following. > > query = > str(table.insert().values(**kwargs).compile(dialect=MySQLDialect(paramstyle='pyformat'))) > > However, if the table has literal default values for any of the columns, > those column names end up in the generated SQL statement as variables even if > kwargs does not contain that key .
that's not true, what you describe is the opposite of SQLAlchemy's policy on database-side defaults. If a column is defined with a server side default, and the key is not in kwargs, it is not rendered in the SQL statement - otherwise there'd be no way for SQLalchemy to support such defaults ! the error in your code is that you're using "default" which is for a Python side default rather than "server_default" which is for a server side default. http://www.sqlalchemy.org/docs/core/schema.html#server-side-defaults -- 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.