Builds and executes an insert statement.

    :param table_name: the name of the table to insert into
    :param values: can be either a dict or an enumerable of 2-tuples in the form (column, value).
    :param returning: the columns to return after updating. Only works for cores that support the
                      returning syntax
    :param upsert: an Upsert instance, defining how to perform the uspert.
    :return: a cursor object

def insert(self, table_name, values, *, returning=None, upsert=None):
    """Builds and executes an insert statement.

    :param table_name: the name of the table to insert into
    :param values: can be either a dict or an enumerable of 2-tuples in the form (column, value).
    :param returning: the columns to return after updating. Only works for cores that support the
                      returning syntax
    :param upsert: an Upsert instance, defining how to perform the uspert.
    :return: a cursor object
    """
    if isinstance(values, dict):
      names = values.keys()
      placeholders = [self.sql_writer.to_placeholder(i) for i in names]
      params = values
    else:
      names = [i[0] for i in values]
      placeholders = [self.sql_writer.to_placeholder() for i in values]
      params = [i[1] for i in values]
    placeholders = self.sql_writer.to_tuple(placeholders)
    names = self.sql_writer.to_tuple(names)
    returns = ""
    if returning and self.core.supports_returning_syntax:
      returns = " returning {0}".format(returning)

    if upsert:
      if upsert.action == Upsert.DO_NOTHING:
        u_action_fmt = " on conflict{} do nothing"
        u_assignments = None
        u_constraints = None
      else:
        u_action_fmt = " on conflict{} do update set {}{}"
        u_assignments, u_assignment_params = self.sql_writer.parse_constraints(
          values, ", ", is_assignment=True)
        u_constraints = ""

        if isinstance(values, dict):
          if not upsert.force:
            # Build constraints based on the full column name, and using !=. This will make it so
            # that the record won't be updated if all the fields we care about are the same.
            u_constraints, u_params = self.core.sql_writer.parse_constraints(
              {"{}.{}".format(table_name, k): v for k, v in values.items()},
              " or ",
              comp="!=")
            params.update(u_params)
        else:
          # Add assignment params
          params.extend(u_assignment_params)

          if not upsert.force:
            # Build constraints based on the full column name, and using !=. This will make it so
            # that the record won't be updated if all the fields we care about are the same.
            u_constraints, u_params = self.core.sql_writer.parse_constraints(
              [("{}.{}".format(table_name, col), val, "!=") for (col, val, *_) in values],
              " or ")
            params.extend(u_params)

      if u_constraints:
        u_constraints = " where {}".format(u_constraints)

      u_action_str = u_action_fmt.format(upsert.target_str or "", u_assignments, u_constraints)

      sql = "insert into {0} {1} values {2}{3}{4}".format(
        table_name,
        names,
        placeholders,
        u_action_str,
        returns)
    else:
      sql = "insert into {0} {1} values {2}{3};".format(table_name, names, placeholders, returns)

    cr = self.execute(sql, params)
    return cr