import re


def _extract_query(message_series):
    """
    Extract SQL queries from the CSVLOG's message column.

    Parameters
    ----------
    message_series : pd.Series
        A series corresponding to the message column of a CSVLOG file.

    Returns
    -------
    query : pd.Series
        A str-typed series containing the queries from the log.
    """
    simple = r"statement: ((?:DELETE|INSERT|SELECT|UPDATE).*)"
    extended = r"execute .+: ((?:DELETE|INSERT|SELECT|UPDATE).*)"
    regex = f"(?:{simple})|(?:{extended})"
    query = message_series.str.extract(regex, flags=re.IGNORECASE)
    # Combine the capture groups for simple and extended query protocol.
    query = query[0].fillna(query[1])
    query.fillna("", inplace=True)
    return query.astype(str)