def find_prev_keyword(sql):
if not sql.strip():<EOL><INDENT>return None, '<STR_LIT>'<EOL><DEDENT>parsed = sqlparse.parse(sql)[<NUM_LIT:0>]<EOL>flattened = list(parsed.flatten())<EOL>logical_operators = ('<STR_LIT>', '<STR_LIT>', '<STR_LIT>', '<STR_LIT>')<EOL>for t in reversed(flattened):<EOL><INDENT>if t.value == '<STR_LIT:(>' or (t.is_keyword and (<EOL>t.value.upper() not in logical_operators)):<EOL><INDENT>idx = flattened.index(t)<EOL>text = '<STR_LIT>'.join(tok.value for tok in flattened[:idx+<NUM_LIT:1>])<EOL>return t, text<EOL><DEDENT><DEDENT>return None, '<STR_LIT>'<EOL>
Find the last sql keyword in an SQL statement
    Returns the value of the last keyword, and the text of the query with
    everything after the last keyword stripped