not sure what the question is - how to use server-side defaults ?    Column 
accepts a "server_default" keyword for this purpose.    You leave the key out 
of the  columns dictionary for those columns where you want the server_default 
to fire off.

if the question is, I want to multiple insert like [{'a':1, 'b':2, 'c':3}, 
{'a':2}, {'a':3, 'b':4}], etc. only some dictionaries are missing different 
keys, that is not allowed.   The structure of the SQL statement as parsed by 
MySQL determines for which columns the server-side default is emitted and there 
is only one version of that with an executemany.   So every param dictionary 
must have at least all the keys which the first one does.

SQLAlchemy also allows "client side" defaults, but the rules are the same for 
executemany(), since SQLalchemy wants to keep the behaviors consistent and 
doesn't want to spend time scanning through the parameter list if its not 
needed.



On May 18, 2010, at 6:53 PM, Dan K wrote:

> I found a similar thread from about a year ago (http://
> groups.google.com/group/sqlalchemy/browse_thread/thread/
> 66ef04fd10fd2be/ec7784b70abedabe), but it never seemed to answer the
> most burning question: is there a way in sqlalchemy to do a multiple
> insert with default values for unspecified columns?  One way this
> might be possible in SQL is to use the DEFAULT keyword, but I haven't
> found anything about it in sqlalchemy.
> 
> Below I have SQL that shows:
> a) the current response of sqlalchemy to a multiple insert with a row
> dict missing a value for a column.
> b) the usage of the DEFAULT keyword I am referring to
> 
> mysql> create table testytest ( mycol int(11) default 5 );
> Query OK, 0 rows affected (0.00 sec)
> 
> mysql> insert into testytest (mycol) values (NULL);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> insert into testytest (mycol) values (DEFAULT);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> insert into testytest (mycol) values (12);
> Query OK, 1 row affected (0.00 sec)
> 
> mysql> select * from testytest;
> +-------+
> | mycol |
> +-------+
> |  NULL |
> |     5 |
> |    12 |
> +-------+
> 3 rows in set (0.00 sec)
> 
> This is trivial seeming in the single insert case, but it seems like
> in the multiple insert case, sqlalchemy will require me to use
> NULLable columns and ignore defaults.  Am I missing something?
> 
> -- 
> 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