23
23
from collections import defaultdict
24
24
25
25
import sqlalchemy as sa
26
- from sqlalchemy .sql import crud , selectable
27
- from sqlalchemy .sql import compiler
28
26
from .types import MutableDict
29
27
from .sa_version import SA_VERSION , SA_1_1 , SA_1_4
30
28
29
+ crud = sa .sql .crud
30
+ selectable = sa .sql .selectable
31
+ compiler = sa .sql .compiler
32
+
31
33
32
34
INSERT_SELECT_WITHOUT_PARENTHESES_MIN_VERSION = (1 , 0 , 1 )
33
35
@@ -521,6 +523,10 @@ def visit_update_14(self, update_stmt, **kw):
521
523
else :
522
524
dialect_hints = None
523
525
526
+ if update_stmt ._independent_ctes :
527
+ for cte in update_stmt ._independent_ctes :
528
+ cte ._compiler_dispatch (self , ** kw )
529
+
524
530
text += table_text
525
531
526
532
text += " SET "
@@ -580,8 +586,9 @@ def visit_update_14(self, update_stmt, **kw):
580
586
update_stmt , self .returning or update_stmt ._returning
581
587
)
582
588
583
- if self .ctes and toplevel :
584
- text = self ._render_cte_clause () + text
589
+ if self .ctes :
590
+ nesting_level = len (self .stack ) if not toplevel else None
591
+ text = self ._render_cte_clause (nesting_level = nesting_level ) + text
585
592
586
593
self .stack .pop (- 1 )
587
594
@@ -602,7 +609,7 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
602
609
from sqlalchemy .sql .crud import _create_bind_param
603
610
from sqlalchemy .sql .crud import REQUIRED
604
611
from sqlalchemy .sql .crud import _get_stmt_parameter_tuples_params
605
- from sqlalchemy .sql .crud import _get_multitable_params
612
+ from sqlalchemy .sql .crud import _get_update_multitable_params
606
613
from sqlalchemy .sql .crud import _scan_insert_from_select_cols
607
614
from sqlalchemy .sql .crud import _scan_cols
608
615
from sqlalchemy import exc # noqa: F401
@@ -682,7 +689,7 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
682
689
# special logic that only occurs for multi-table UPDATE
683
690
# statements
684
691
if compile_state .isupdate and compile_state .is_multitable :
685
- _get_multitable_params (
692
+ _get_update_multitable_params (
686
693
compiler ,
687
694
stmt ,
688
695
compile_state ,
@@ -738,9 +745,18 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
738
745
739
746
if compile_state ._has_multi_parameters :
740
747
values = _extend_values_for_multiparams (
741
- compiler , stmt , compile_state , values , kw
748
+ compiler ,
749
+ stmt ,
750
+ compile_state ,
751
+ values ,
752
+ _column_as_key ,
753
+ kw ,
742
754
)
743
- elif not values and compiler .for_executemany :
755
+ elif (
756
+ not values
757
+ and compiler .for_executemany # noqa: W503
758
+ and compiler .dialect .supports_default_metavalue # noqa: W503
759
+ ):
744
760
# convert an "INSERT DEFAULT VALUES"
745
761
# into INSERT (firstcol) VALUES (DEFAULT) which can be turned
746
762
# into an in-place multi values. This supports
0 commit comments