Inspecting query column names
This type of question is more appropriate to stackoverflow.

However...when you create a query, you necessarily know what columns are being selected. So how can there be a problem? Because you may want to write your code in such a way that it can be reused without passing the names of columns explicitly, especially because this information is already part of the results object.

It appears that you get a different API depending on whether speedups are enabled. With speedups disabled, there is a `column_meta` attribute on peewee.NaiveQueryResultWrapper that exposes all the metadata.

```
>>> type(results)
<class 'peewee.NaiveQueryResultWrapper'>
>>> for f in results.column_meta: print(f.name)
obsid
pi_last_name
obs_date
exptime
``` > Because you may want to write your code in such a way that it can be reused without passing the names of columns explicitly, especially because this information is already part of the results object.

I definitely get that...especially in a template, like your example.

I've updated the speedups module to expose the column_meta attribute, see f11802807f5e05dddeb32f93b8c84703b49bb498
I have some code that spits out an HTML table from some query results:

```python
    <table>
      <tr>{% for column in columns %}<th>{{ column }}</th>{% endfor %}<th>
    {% for result in results %}
      <tr>{% for column in columns %}<td>{{ result[column] }}</td>{% endfor %}</tr>
    {% endfor %}
    </table>
```

The best way I've found so far to get the `columns` from the query is:

```
results = query.execute()
first_row = results.next()
columns = first_row._meta.sorted_field_names
```

Is there a better way? (Incidentally, it's surprising to me that `list(results)` acts the same whether or not I call `results.next()`...)