I need to obtain the name of the columns from a query and also the name of the table from which the column comes, reviewing the documentation of pyodbc I have managed to obtain the name of the columns but I can not get the name, the problem is that in the query there are two tables, and I need to get which field belongs to that table.
select parroquia.nombre,canton.idcanton,canton.codigo,
canton.descripcion from pcparroquia
inner join pccanton on canton.idcanton = parroquia.idcanton
where parroquia.idparroquia is not null
Python
results = cursor.execute(query)
columns = [{'field': info[0], 'type': str(info[1]).split('\'')[1]} for info in
results.description]
The expected result would be:
[
{
'field': 'nombre',
'table': 'parroquia'
},
{
'field': 'codigo',
'table': 'canton'
},
{
'field': 'descripcion',
'table': 'canton'
}
]
Thanks in advance.