def visit_update(self, update_stmt, asfrom=False, **kw):
        if not self.dialect.supports_update:
            raise exc.CompileError(
                'ALTER UPDATE is not supported by this server version'
            )

        render_extra_froms = []
        correlate_froms = {update_stmt.table}

        self.stack.append(
            {
                "correlate_froms": correlate_froms,
                "asfrom_froms": correlate_froms,
                "selectable": update_stmt,
            }
        )

        text = "ALTER TABLE "

        table_text = self.update_tables_clause(
            update_stmt, update_stmt.table, render_extra_froms, **kw
        )
        crud_params = crud._setup_crud_params(
            self, update_stmt, crud.ISUPDATE, **kw
        )

        text += table_text
        text += " UPDATE "

        text += ", ".join(
            c[0]._compiler_dispatch(self, include_table=False) +
            "=" + c[1]
            for c in crud_params
        )

        if update_stmt._whereclause is not None:
            # Do not include table name.
            # ClickHouse doesn't expect tablename in where.
            t = self.process(update_stmt._whereclause, include_table=False,
                             **kw)
            if t:
                text += " WHERE " + t
        else:
            raise exc.CompileError('WHERE clause is required')

        self.stack.pop(-1)

        return text
Exemple #2
0
    def visit_update(self, update_stmt, asfrom=False, **kw):
        extra_froms = update_stmt._extra_froms
        is_multitable = bool(extra_froms)

        render_extra_froms = []
        correlate_froms = {update_stmt.table}
        self.stack.append(
            {
                "correlate_froms": correlate_froms,
                "asfrom_froms": correlate_froms,
                "selectable": update_stmt,
            }
        )

        text = "ALTER TABLE "

        table_text = self.update_tables_clause(
            update_stmt, update_stmt.table, render_extra_froms, **kw
        )
        crud_params = crud._setup_crud_params(
            self, update_stmt, crud.ISUPDATE, **kw
        )

        text += table_text
        text += " UPDATE "

        include_table = (
            is_multitable and self.render_table_with_column_in_update_from
        )

        text += ", ".join(
            c[0]._compiler_dispatch(self, include_table=include_table) +
            "=" + c[1]
            for c in crud_params
        )

        if update_stmt._whereclause is not None:
            t = self.process(update_stmt._whereclause, **kw)
            if t:
                text += " WHERE " + t

        self.stack.pop(-1)

        return text