[Sqlalchemy-tickets] Issue #4155: can't send column objects as keys to insert w/ multivalues (zzzee
Brought to you by:
zzzeek
From: Michael B. <iss...@bi...> - 2018-01-05 20:09:09
|
New issue 4155: can't send column objects as keys to insert w/ multivalues https://bitbucket.org/zzzeek/sqlalchemy/issues/4155/cant-send-column-objects-as-keys-to-insert Michael Bayer: ML thread https://groups.google.com/forum/?hl=en#!topic/sqlalchemy/t8a6SLTYrIc even though all the docs show string names being sent to insert.values(), you can use columns as keys inside a dictionary as well, just as we need to do with UPDATE some times. It doesn't work for multi-values though: ``` #!python 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())) ``` gerrit at https://gerrit.sqlalchemy.org/#/c/zzzeek/sqlalchemy/+/626 fixes. |