(parsed)
| 113 | |
| 114 | |
| 115 | def extract_column_names(parsed): |
| 116 | # Find the first DML token to check if it's a SELECT or INSERT/UPDATE/DELETE |
| 117 | idx, tok = parsed.token_next_by(t=DML) |
| 118 | tok_val = tok and tok.value.lower() |
| 119 | |
| 120 | if tok_val in ('insert', 'update', 'delete'): |
| 121 | # Jump ahead to the RETURNING clause where the list of column names is |
| 122 | idx, tok = parsed.token_next_by(idx, (Keyword, 'returning')) |
| 123 | elif not tok_val == 'select': |
| 124 | # Must be invalid CTE |
| 125 | return () |
| 126 | |
| 127 | # The next token should be either a column name, or a list of column names |
| 128 | idx, tok = parsed.token_next(idx, skip_ws=True, skip_cm=True) |
| 129 | return tuple(t.get_name() for t in _identifiers(tok)) |
| 130 | |
| 131 | |
| 132 | def token_start_pos(tokens, idx): |
no test coverage detected