html_url,issue_url,id,node_id,user,created_at,updated_at,author_association,body,reactions,issue,performed_via_github_app
https://github.com/simonw/datasette/issues/1080#issuecomment-1029695083,https://api.github.com/repos/simonw/datasette/issues/1080,1029695083,IC_kwDOBm6k_c49X-Zr,9599,2022-02-04T06:24:40Z,2022-02-04T06:25:18Z,OWNER,"An initial prototype of that in my local `group-count` branch quickly started running into problems:
```diff
diff --git a/datasette/views/table.py b/datasette/views/table.py
index be9e9c3..d30efe1 100644
--- a/datasette/views/table.py
+++ b/datasette/views/table.py
@@ -105,8 +105,12 @@ class RowTableShared(DataView):
type_ = ""integer""
notnull = 0
else:
- type_ = column_details[r[0]].type
- notnull = column_details[r[0]].notnull
+ try:
+ type_ = column_details[r[0]].type
+ notnull = column_details[r[0]].notnull
+ except KeyError: # Probably count(*)
+ type_ = ""integer""
+ notnull = False
columns.append(
{
""name"": r[0],
@@ -613,6 +617,15 @@ class TableView(RowTableShared):
offset=offset,
)
+ # If ?_group_count we convert the SQL query here
+ group_count = request.args.getlist(""_group_count"")
+ if group_count:
+ wrapped_sql = ""select {cols}, count(*) from ({sql}) group by {cols}"".format(
+ cols="", "".join(group_count),
+ sql=sql,
+ )
+ sql = wrapped_sql
+
if request.args.get(""_timelimit""):
extra_args[""custom_time_limit""] = int(request.args.get(""_timelimit""))
```
Resulted in errors like this one:
```
pk_path = path_from_row_pks(row, pks, not pks, False)
File ""/Users/simon/Dropbox/Development/datasette/datasette/utils/__init__.py"", line 82, in path_from_row_pks
bits = [
File ""/Users/simon/Dropbox/Development/datasette/datasette/utils/__init__.py"", line 83, in
row[pk][""value""] if isinstance(row[pk], dict) else row[pk] for pk in pks
IndexError: No item with that key
```","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",734777631,
https://github.com/simonw/datasette/issues/1080#issuecomment-1029691693,https://api.github.com/repos/simonw/datasette/issues/1080,1029691693,IC_kwDOBm6k_c49X9kt,9599,2022-02-04T06:16:45Z,2022-02-04T06:16:45Z,OWNER,"Had a new, different idea for how this could work: support a `?_group_count=colname` parameter to the table view, which turns the page into a `select colname, count(*) ... group by colname` query - but keeps things like the filter interface, facet selection, search box and so on.","{""total_count"": 0, ""+1"": 0, ""-1"": 0, ""laugh"": 0, ""hooray"": 0, ""confused"": 0, ""heart"": 0, ""rocket"": 0, ""eyes"": 0}",734777631,