diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-12-19 16:02:14 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-12-19 16:02:14 -0500 |
commit | 5f76f29c15b7a23cfe29c5fbd22ad02452b6a2c0 (patch) | |
tree | 022779ebba8df3b7d75d4c46fa7730f0f2d1fda5 /lib/sqlalchemy/sql/dml.py | |
parent | 47eb5682d1b8885c052e4bc50004af45b5f19174 (diff) | |
download | sqlalchemy-5f76f29c15b7a23cfe29c5fbd22ad02452b6a2c0.tar.gz |
- Fixed bug with :meth:`.Insert.from_select` method where the order
of the given names would not be taken into account when generating
the INSERT statement, thus producing a mismatch versus the column
names in the given SELECT statement. Also noted that
:meth:`.Insert.from_select` implies that Python-side insert defaults
cannot be used, since the statement has no VALUES clause. [ticket:2895]
Diffstat (limited to 'lib/sqlalchemy/sql/dml.py')
-rw-r--r-- | lib/sqlalchemy/sql/dml.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/sqlalchemy/sql/dml.py b/lib/sqlalchemy/sql/dml.py index 3501417a4..83f4365d7 100644 --- a/lib/sqlalchemy/sql/dml.py +++ b/lib/sqlalchemy/sql/dml.py @@ -426,7 +426,7 @@ class Insert(ValuesBase): """ ValuesBase.__init__(self, table, values, prefixes) self._bind = bind - self.select = None + self.select = self.select_names = None self.inline = inline self._returning = returning self.kwargs = kwargs @@ -470,6 +470,13 @@ class Insert(ValuesBase): sel = select([table1.c.a, table1.c.b]).where(table1.c.c > 5) ins = table2.insert(inline=True).from_select(['a', 'b'], sel) + .. note:: + + A SELECT..INSERT construct in SQL has no VALUES clause. Therefore + :class:`.Column` objects which utilize Python-side defaults + (e.g. as described at :ref:`metadata_defaults_toplevel`) + will **not** take effect when using :meth:`.Insert.from_select`. + .. versionadded:: 0.8.3 """ @@ -480,6 +487,7 @@ class Insert(ValuesBase): self.parameters, self._has_multi_parameters = \ self._process_colparams(dict((n, Null()) for n in names)) + self.select_names = names self.select = _interpret_as_select(select) def _copy_internals(self, clone=_clone, **kw): |