Thanx Brian.. I too thought of something similar- concatenating to create 
the sql ..Since executing multiple statements is quite common, I thought 
something inbuilt will be there in web2py..
I dug through the code and found a executemany() function in  gluon/contrib/
pg8000/dbapi.py  ..Will it serve the purpose? Is it accessible through DAL?

On Monday, August 12, 2013 3:27:22 AM UTC+5:30, Brian M wrote:
>
> Sorry, not totally sure how to fix it, but what you've got now is quite 
> confused. You've got just 2 placeholders in your SQL statement "values(%s, 
> %s)" but 3 in placeholderlist so right there it isn't going to work. Plus, 
> you don't want "values([val1, val2], [val3, val4]) in the final SQL anyway 
> you want "values(val1, val2)".
>  
> Just a guess (totally untested), but to get this to work you may have to 
> make your SQL query dynamically.
>
> placeholderlist=[[val1a,val2a], [val1b,val2b], [val1c,val2c]]
> #you've got 3 sets of values, so you'll need 3 values(%s, %s) in the sql - 
> add in the necessary values(%s, %s) dynamically based on 
> len(placeholderslist)
> value_placeholders = ', '.join(['values(%s, %s)']*len(placeholderslist))
> sql = "insert into mytable(col1,col2) "+value_placeholders
> #and you'd then need all of those value pairs in a single flattened list, 
> again actually do dynamically
> placeholders = []
> for v in placeholderslist:
>     placeholders.extend(v)
> #gives placeholders = [val1a, val2a, val1b, val2b, val1c, val2c]
> #and then hopefully this would work
> db.executesql(sql, placeholders)
> #hopefully ends up with
> #INSERT INTO mytable(col1, col2) values(val1a, val2a), values(val2a, 
> val2b), values(val3a, val3b)
>
> Again I haven't tested this, don't even have postgresql installed at the 
> moment but give it a shot.
>
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to