psqlextra/compiler.py
def _rewrite_insert_update(self, sql, params, returning):
        """Rewrites a formed SQL INSERT query to include
        the ON CONFLICT DO UPDATE clause."""

        update_columns = ', '.join([
            '{0} = EXCLUDED.{0}'.format(self.qn(field.column))
            for field in self.query.update_fields
        ])

        # build the conflict target, the columns to watch
        # for conflicts
        conflict_target = self._build_conflict_target()

        index_predicate = self.query.index_predicate

        sql_template = (
            '{insert} ON CONFLICT {conflict_target} DO UPDATE '
            'SET {update_columns} RETURNING {returning}'
        )

        if index_predicate:
            sql_template = (
                '{insert} ON CONFLICT {conflict_target} WHERE {index_predicate} DO UPDATE '
                'SET {update_columns} RETURNING {returning}'
            )

        return (
            sql_template.format(
                insert=sql,
                conflict_target=conflict_target,
                update_columns=update_columns,
                returning=returning,
                index_predicate=index_predicate,
            ),
            params
        )
def _rewrite_insert_update(self, sql, params, returning):
        """Rewrites a formed SQL INSERT query to include
        the ON CONFLICT DO UPDATE clause."""

        update_columns = ', '.join([
            '{0} = EXCLUDED.{0}'.format(self.qn(field.column))
            for field in self.query.update_fields
        ])

        # build the conflict target, the columns to watch
        # for conflicts
        conflict_target = self._build_conflict_target()

        index_predicate = self.query.index_predicate

        sql_template = (
            '{insert} ON CONFLICT {conflict_target} DO UPDATE '
            'SET {update_columns} RETURNING {returning}'
        )

        if index_predicate:
            sql_template = (
                '{insert} ON CONFLICT {conflict_target} WHERE {index_predicate} DO UPDATE '
                'SET {update_columns} RETURNING {returning}'
            )

        return (
            sql_template.format(
                insert=sql,
                conflict_target=conflict_target,
                update_columns=update_columns,
                returning=returning,
                index_predicate=index_predicate,
            ),
            params
        )
def _rewrite_insert_update ( self , sql , params , returning ) : update_columns = ', ' . join ( [ '{0} = EXCLUDED.{0}' . format ( self . qn ( field . column ) ) for field in self . query . update_fields ] ) # build the conflict target, the columns to watch # for conflicts conflict_target = self . _build_conflict_target ( ) index_predicate = self . query . index_predicate sql_template = ( '{insert} ON CONFLICT {conflict_target} DO UPDATE ' 'SET {update_columns} RETURNING {returning}' ) if index_predicate : sql_template = ( '{insert} ON CONFLICT {conflict_target} WHERE {index_predicate} DO UPDATE ' 'SET {update_columns} RETURNING {returning}' ) return ( sql_template . format ( insert = sql , conflict_target = conflict_target , update_columns = update_columns , returning = returning , index_predicate = index_predicate , ) , params )
Rewrites a formed SQL INSERT query to include
        the ON CONFLICT DO UPDATE clause.
Rewrites a formed SQL INSERT query to include the ON CONFLICT DO UPDATE clause .