traditional multi-insert is to use executemany() syntax, I'm not sure if sqlite 
supports values () (), anyway.

data = [
  {"id": 1, "value": "foo"},
  {"id": 2, "value": "bar"}
]

stmt = table.insert().values(adate=sql.func.now())
engine.execute(stmt, data)


the func.now() is a constant and the multi-values thing doesn't support 
different constant expressions in each bundle as it would mean lots of 
expensive isinstance() checks, if you just put it in the first element that 
will work also:

data = [
  {"id": 1, "value": "foo", "adate":sql.func.now()},
  {"id": 2, "value": "bar"}
]

stmt = table.insert().values(data)
print stmt






On Jun 3, 2014, at 5:40 PM, Stefan Urbanek <stefan.urba...@gmail.com> wrote:

> Hi,
> 
> I'm trying to multi-insert records which contain a function:
> 
> record = { 
>     "some_date": sql.func.now() 
>     key: value, ...
> } 
> 
> When I execute table insert with list of records where len(records) > 1 then 
> I get an error:
> 
> "sqlalchemy.exc.ProgrammingError: (ProgrammingError) can't adapt type 'now'"
> 
> I noticed something in the string representation of the statement:
> 
> INSERT INTO table (some_date, col1, col2) VALUES (now(), %(col1_0)s, 
> %(col2_0)), (%(some_date_1)s, %(col1_1)s, %(col2_1))
> 
> Note that the first value in the second record is `%(some_date_1)s` instead 
> of `now()`
> 
> What might be wrong?
> 
> Stefan
> 
> -- 
> 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 sqlalchemy+unsubscr...@googlegroups.com.
> To post to this group, send email to sqlalchemy@googlegroups.com.
> Visit this group at http://groups.google.com/group/sqlalchemy.
> For more options, visit https://groups.google.com/d/optout.

-- 
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 sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to