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
26
+ from sqlalchemy .sql import compiler , crud , selectable
28
27
from .types import MutableDict
29
28
from .sa_version import SA_VERSION , SA_1_4
30
29
@@ -400,6 +399,10 @@ def visit_update_14(self, update_stmt, **kw):
400
399
else :
401
400
dialect_hints = None
402
401
402
+ if update_stmt ._independent_ctes :
403
+ for cte in update_stmt ._independent_ctes :
404
+ cte ._compiler_dispatch (self , ** kw )
405
+
403
406
text += table_text
404
407
405
408
text += " SET "
@@ -459,8 +462,9 @@ def visit_update_14(self, update_stmt, **kw):
459
462
update_stmt , self .returning or update_stmt ._returning
460
463
)
461
464
462
- if self .ctes and toplevel :
463
- text = self ._render_cte_clause () + text
465
+ if self .ctes :
466
+ nesting_level = len (self .stack ) if not toplevel else None
467
+ text = self ._render_cte_clause (nesting_level = nesting_level ) + text
464
468
465
469
self .stack .pop (- 1 )
466
470
@@ -481,7 +485,7 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
481
485
from sqlalchemy .sql .crud import _create_bind_param
482
486
from sqlalchemy .sql .crud import REQUIRED
483
487
from sqlalchemy .sql .crud import _get_stmt_parameter_tuples_params
484
- from sqlalchemy .sql .crud import _get_multitable_params
488
+ from sqlalchemy .sql .crud import _get_update_multitable_params
485
489
from sqlalchemy .sql .crud import _scan_insert_from_select_cols
486
490
from sqlalchemy .sql .crud import _scan_cols
487
491
from sqlalchemy import exc # noqa: F401
@@ -561,7 +565,7 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
561
565
# special logic that only occurs for multi-table UPDATE
562
566
# statements
563
567
if compile_state .isupdate and compile_state .is_multitable :
564
- _get_multitable_params (
568
+ _get_update_multitable_params (
565
569
compiler ,
566
570
stmt ,
567
571
compile_state ,
@@ -620,9 +624,18 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
620
624
621
625
if compile_state ._has_multi_parameters :
622
626
values = _extend_values_for_multiparams (
623
- compiler , stmt , compile_state , values , kw
627
+ compiler ,
628
+ stmt ,
629
+ compile_state ,
630
+ values ,
631
+ _column_as_key ,
632
+ kw ,
624
633
)
625
- elif not values and compiler .for_executemany :
634
+ elif (
635
+ not values
636
+ and compiler .for_executemany # noqa: W503
637
+ and compiler .dialect .supports_default_metavalue # noqa: W503
638
+ ):
626
639
# convert an "INSERT DEFAULT VALUES"
627
640
# into INSERT (firstcol) VALUES (DEFAULT) which can be turned
628
641
# into an in-place multi values. This supports
0 commit comments