2323from collections import defaultdict
2424
2525import sqlalchemy as sa
26- from sqlalchemy .sql import crud , selectable
27- from sqlalchemy .sql import compiler
26+ from sqlalchemy .sql import compiler , crud , selectable
2827from .types import MutableDict
2928from .sa_version import SA_VERSION , SA_1_4
3029
@@ -400,6 +399,10 @@ def visit_update_14(self, update_stmt, **kw):
400399 else :
401400 dialect_hints = None
402401
402+ if update_stmt ._independent_ctes :
403+ for cte in update_stmt ._independent_ctes :
404+ cte ._compiler_dispatch (self , ** kw )
405+
403406 text += table_text
404407
405408 text += " SET "
@@ -459,8 +462,9 @@ def visit_update_14(self, update_stmt, **kw):
459462 update_stmt , self .returning or update_stmt ._returning
460463 )
461464
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
464468
465469 self .stack .pop (- 1 )
466470
@@ -481,7 +485,7 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
481485 from sqlalchemy .sql .crud import _create_bind_param
482486 from sqlalchemy .sql .crud import REQUIRED
483487 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
485489 from sqlalchemy .sql .crud import _scan_insert_from_select_cols
486490 from sqlalchemy .sql .crud import _scan_cols
487491 from sqlalchemy import exc # noqa: F401
@@ -561,7 +565,7 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
561565 # special logic that only occurs for multi-table UPDATE
562566 # statements
563567 if compile_state .isupdate and compile_state .is_multitable :
564- _get_multitable_params (
568+ _get_update_multitable_params (
565569 compiler ,
566570 stmt ,
567571 compile_state ,
@@ -620,9 +624,18 @@ def _get_crud_params_14(compiler, stmt, compile_state, **kw):
620624
621625 if compile_state ._has_multi_parameters :
622626 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 ,
624633 )
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+ ):
626639 # convert an "INSERT DEFAULT VALUES"
627640 # into INSERT (firstcol) VALUES (DEFAULT) which can be turned
628641 # into an in-place multi values. This supports
0 commit comments