On Fri, Nov 4, 2011 at 3:57 PM, Michael Bayer <[email protected]>wrote:

>
> 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


Thank you for the pointer to server side defaults.  I actually do want
client side defaults in this case.  i just want a convenient way to get
them.  Looks like I can get them from the compiler.prefetch list.

Thanks,

Roger


>
>
>
> --
> 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.
>
>

-- 
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.

Reply via email to