Hello,

I've just been thrown by what seems like an inconsistency in how parameters can 
be passed to an insert statement that adds multiple rows.

To demonstrate:


from sqlalchemy import MetaData, String, Integer, Table, Column
from sqlalchemy.dialects.postgresql.base import PGDialect

m = MetaData()

t = Table('mytable', m,
    Column('int_col', Integer),
    Column('str_col', String),
)

print("Case 1")

print(t.insert().values(
    {t.c.str_col:"string", t.c.int_col:2}
).compile(dialect=PGDialect()))

print("Case 2")

print(t.insert().values(
    [
        {t.c.str_col:"str", t.c.int_col:1}
    ]
).compile(dialect=PGDialect()))

print("Case 3")

print(t.insert().values(
    [
        {t.c.str_col:"string", t.c.int_col:1},
        {t.c.str_col:"text", t.c.int_col:2}
    ]
).compile(dialect=PGDialect()))


Case 1 and 2 will work but Case 3 will fail.

I believe the this is because
`sqlalchemy.sql.crud._extend_values_for_multiparams` only searches for string 
keys in each row. I altered the function to check for a column object or a 
string and Case 3 produced the expected output after this.

I'm still getting used to sqlalchemy and I am unsure if this is intended, but 
it certainly took me by surprise. If it's not intentional, the fix seems very 
minor - I'd be happy to attempt a patch.

Cheers,
Aubrey

-- 
SQLAlchemy - 
The Python SQL Toolkit and Object Relational Mapper

http://www.sqlalchemy.org/

To post example code, please provide an MCVE: Minimal, Complete, and Verifiable 
Example.  See  http://stackoverflow.com/help/mcve for a full description.
--- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.

Reply via email to