simonw / django-sql-dashboard

Django app for building dashboards using raw SQL queries
https://django-sql-dashboard.datasette.io/
Apache License 2.0
437 stars 37 forks source link

Support multiple colums with the same name #52

Closed simonw closed 3 years ago

simonw commented 3 years ago

I tried this query:

select * from report join location on report.location_id = location.id join state on location.state_id = state.id where state.abbreviation = 'CA' order by report.id desc limit 100

And the resulting table had weird values in the id column - because all three of those tables returned an ID and we run them through a dictionary, which means the last one wins.

simonw commented 3 years ago

Here's the cause of the bug: https://github.com/simonw/django-sql-dashboard/blob/9f792ec5ebbf111bdc3d9ea80da81bbc940e071e/django_sql_dashboard/views.py#L140-L156

In particular this bit: https://github.com/simonw/django-sql-dashboard/blob/9f792ec5ebbf111bdc3d9ea80da81bbc940e071e/django_sql_dashboard/views.py#L153-L156