I would like to extract the column names of a resulting table directly from the SQL statement:
query = """
select
sales.order_id as id,
p.product_name,
sum(p.price) as sales_volume
from sales
right join products as p
on sales.product_id=p.product_id
group by id, p.product_name;
"""
column_names = parse_sql(query)
# column_names:
# ['id', 'product_name', 'sales_volume']
Any idea what to do in parse_sql()? The resulting function should be able to recognize aliases and remove the table aliases/identifiers (e.g. "sales." or "p.").
Thanks in advance!
python-sqlparselibrary.