Fixed bug where tables with a column called n caused 500 errors

Closes #1228
This commit is contained in:
Simon Willison 2022-03-18 18:37:54 -07:00
commit 4e47a2d894
7 changed files with 59 additions and 37 deletions

View file

@ -151,10 +151,10 @@ class ColumnFacet(Facet):
if column in already_enabled:
continue
suggested_facet_sql = """
select {column}, count(*) as n from (
select {column} as value, count(*) as n from (
{sql}
) where {column} is not null
group by {column}
) where value is not null
group by value
limit {limit}
""".format(
column=escape_sqlite(column), sql=self.sql, limit=facet_size + 1