| 581 | |
| 582 | |
| 583 | def _key_getters_for_crud_column( |
| 584 | compiler: SQLCompiler, stmt: ValuesBase, compile_state: DMLState |
| 585 | ) -> Tuple[ |
| 586 | Callable[[Union[str, ColumnClause[Any]]], Union[str, Tuple[str, str]]], |
| 587 | Callable[[ColumnClause[Any]], Union[str, Tuple[str, str]]], |
| 588 | _BindNameForColProtocol, |
| 589 | ]: |
| 590 | if dml.isupdate(compile_state) and compile_state._extra_froms: |
| 591 | # when extra tables are present, refer to the columns |
| 592 | # in those extra tables as table-qualified, including in |
| 593 | # dictionaries and when rendering bind param names. |
| 594 | # the "main" table of the statement remains unqualified, |
| 595 | # allowing the most compatibility with a non-multi-table |
| 596 | # statement. |
| 597 | _et = set(compile_state._extra_froms) |
| 598 | |
| 599 | c_key_role = functools.partial( |
| 600 | coercions.expect_as_key, roles.DMLColumnRole |
| 601 | ) |
| 602 | |
| 603 | def _column_as_key( |
| 604 | key: Union[ColumnClause[Any], str], |
| 605 | ) -> Union[str, Tuple[str, str]]: |
| 606 | str_key = c_key_role(key) |
| 607 | if hasattr(key, "table") and key.table in _et: |
| 608 | return (key.table.name, str_key) # type: ignore |
| 609 | else: |
| 610 | return str_key |
| 611 | |
| 612 | def _getattr_col_key( |
| 613 | col: ColumnClause[Any], |
| 614 | ) -> Union[str, Tuple[str, str]]: |
| 615 | if col.table in _et: |
| 616 | return (col.table.name, col.key) # type: ignore |
| 617 | else: |
| 618 | return col.key |
| 619 | |
| 620 | def _col_bind_name(col: ColumnClause[Any]) -> str: |
| 621 | if col.table in _et: |
| 622 | if TYPE_CHECKING: |
| 623 | assert isinstance(col.table, TableClause) |
| 624 | return "%s_%s" % (col.table.name, col.key) |
| 625 | else: |
| 626 | return col.key |
| 627 | |
| 628 | else: |
| 629 | _column_as_key = functools.partial( |
| 630 | coercions.expect_as_key, roles.DMLColumnRole |
| 631 | ) |
| 632 | _getattr_col_key = _col_bind_name = operator.attrgetter("key") # type: ignore # noqa: E501 |
| 633 | |
| 634 | return _column_as_key, _getattr_col_key, _col_bind_name |
| 635 | |
| 636 | |
| 637 | def _scan_insert_from_select_cols( |