<p dir="auto"><strong>Migrated issue, originally created by Michael Bayer (<a href="https://github.com/zzzeek">@zzzeek</a>)</strong></p>
<p dir="auto">ML thread <a href="https://groups.google.com/forum/?hl=en#!topic/sqlalchemy/t8a6SLTYrIc" rel="nofollow">https://groups.google.com/forum/?hl=en#!topic/sqlalchemy/t8a6SLTYrIc</a></p>
<p dir="auto">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:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="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(&quot;Case 1&quot;)

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

print(&quot;Case 2&quot;)

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

print(&quot;Case 3&quot;)

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

"><pre class="notranslate"><code class="notranslate">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()))


</code></pre></div>
<p dir="auto">gerrit at <a href="https://gerrit.sqlalchemy.org/#/c/zzzeek/sqlalchemy/+/626" rel="nofollow">https://gerrit.sqlalchemy.org/#/c/zzzeek/sqlalchemy/+/626</a> fixes.</p>
<p dir="auto"><strong>Migrated issue, originally created by Michael Bayer (<a href="https://github.com/zzzeek">@zzzeek</a>)</strong></p>
<p dir="auto">even though columns-as-keys is de-emphasized in the documentation for insert, it does work, except for multi-values:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from sqlalchemy import *
from sqlalchemy.dialects import sqlite

t = table('t', column('a'), column('b'))

print t.insert().values([
    {&quot;a&quot;: 1, &quot;b&quot;: 2},
    {&quot;a&quot;: 2, &quot;b&quot;: 2},
    {&quot;a&quot;: 3, &quot;b&quot;: 2}
]).compile(dialect=sqlite.dialect())


print t.insert().values([
    {t.c.a: 1, t.c.b: 2},
    {t.c.a: 2, t.c.b: 2},
    {t.c.a: 3, t.c.b: 2},
]).compile(dialect=sqlite.dialect())"><pre class="notranslate"><code class="notranslate">from sqlalchemy import *
from sqlalchemy.dialects import sqlite

t = table('t', column('a'), column('b'))

print t.insert().values([
    {"a": 1, "b": 2},
    {"a": 2, "b": 2},
    {"a": 3, "b": 2}
]).compile(dialect=sqlite.dialect())


print t.insert().values([
    {t.c.a: 1, t.c.b: 2},
    {t.c.a: 2, t.c.b: 2},
    {t.c.a: 3, t.c.b: 2},
]).compile(dialect=sqlite.dialect())
</code></pre></div>
<p dir="auto">output:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="#!

INSERT INTO t (a, b) VALUES (?, ?), (?, ?), (?, ?)
Traceback (most recent call last):
...
  File &quot;/home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/crud.py&quot;, line 419, in _process_multiparam_default_bind
    &quot;a Python-side value or SQL expression is required&quot; % c)
sqlalchemy.exc.CompileError: INSERT value for column t.a is explicitly rendered as a boundparameter in the VALUES clause; a Python-side value or SQL expression is required
"><pre class="notranslate"><code class="notranslate">#!

INSERT INTO t (a, b) VALUES (?, ?), (?, ?), (?, ?)
Traceback (most recent call last):
...
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/sql/crud.py", line 419, in _process_multiparam_default_bind
    "a Python-side value or SQL expression is required" % c)
sqlalchemy.exc.CompileError: INSERT value for column t.a is explicitly rendered as a boundparameter in the VALUES clause; a Python-side value or SQL expression is required

</code></pre></div>