Issues

Issue #3069 resolved

multi-valued insert isn't checking additonal values for literal

Mike Bayer
repo owner created an issue
from sqlalchemy import create_engine, MetaData, Table, Integer, Date, Column
import sqlalchemy.sql as sql

md = MetaData()
table = Table("data", md)
table.append_column(Column("id", Integer))
table.append_column(Column("adate", Date))
table.append_column(Column("value", Integer))

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

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

from sqlalchemy.dialects import postgresql
print stmt.compile(dialect=postgresql.dialect())
INSERT INTO data (id, adate, value) VALUES (%(id_0)s, now(), %(value_0)s), (%(id_1)s, %(adate_1)s, %(value_1)s)

patch:

index cd01ea5..dff4c99 100644
--- a/lib/sqlalchemy/sql/compiler.py
+++ b/lib/sqlalchemy/sql/compiler.py
@@ -2207,10 +2207,12 @@ class SQLCompiler(Compiled):
                 [
                     (
                         c,
-                            self._create_crud_bind_param(
+                            (self._create_crud_bind_param(
                                     c, row[c.key],
                                     name="%s_%d" % (c.key, i + 1)
-                            )
+                            ) if elements._is_literal(row[c.key])
+                                else self.process(
+                                            row[c.key].self_group(), **kw))
                             if c.key in row else param
                     )
                     for (c, param) in values_0

the current behavior is totally wrong. safe to go in

Comments (7)

  1. Log in to comment