[Sqlalchemy-tickets] Issue #3418: preserve CTE from a SELECT when doing INSERT...SELECT (zzzeek/sql
Brought to you by:
zzzeek
|
From: Mike B. <iss...@bi...> - 2015-05-08 16:12:01
|
New issue 3418: preserve CTE from a SELECT when doing INSERT...SELECT https://bitbucket.org/zzzeek/sqlalchemy/issue/3418/preserve-cte-from-a-select-when-doing Mike Bayer: related to #2551 but of lesser scope, if the select() passed to insert.from_select() has a cte() inside of it, we should render that inline: ``` #!sql INSERT INTO data (id, data) WITH anon_1 AS (SELECT data2.id AS id, data2.data AS data FROM data2 WHERE data2.data = 1) SELECT data2.id, data2.data FROM data2, anon_1 WHERE data2.data = anon_1.data ``` PG supports the WITH both on top and under the INSERT, and they have different semantics: http://www.postgresql.org/docs/9.4/interactive/sql-insert.html "It is possible for the query (SELECT statement) to also contain a WITH clause. In such a case both sets of with_query can be referenced within the query, but the second one takes precedence since it is more closely nested.". |