If we want to retrieve the unique values of a column, the best current syntax would be ?<col_name>__groupby, but it doesn't work as expected: without any aggregation operator in the query (like sum or mean), the returned data only contains the value of the col_name column for each row, as they appear in the table.
This can be explained as the Postgrest query is then select=<col_name>, which only selects the values, without performing any additional operation, including a groupby. A current way to achieve a real groupby is to add an aggregation operation to the query.
Example:
https://tabular-api.data.gouv.fr/api/resources/75a43900-a916-4105-adcf-fe88f88194a8/data/?inseecommuneprinc__isnotnull&inseecommuneprinc__groupby
yields
{
"data": [
{
"inseecommuneprinc": "01007"
},
{
"inseecommuneprinc": "01007"
},
{
"inseecommuneprinc": "01007"
},
{
"inseecommuneprinc": "01007"
},
{
"inseecommuneprinc": "01007"
},
{
"inseecommuneprinc": "01006"
},
...
whereas https://tabular-api.data.gouv.fr/api/resources/75a43900-a916-4105-adcf-fe88f88194a8/data/?inseecommuneprinc__isnotnull&inseecommuneprinc__groupby&annee__sum
yields
{
"data": [
{
"inseecommuneprinc": "01001",
"annee__sum": 58593
},
{
"inseecommuneprinc": "01002",
"annee__sum": 181913
},
{
"inseecommuneprinc": "01004",
"annee__sum": 1353962
},
{
"inseecommuneprinc": "01005",
"annee__sum": 131522
},
...
(without duplicates)
Possible solutions:
- understand that with only one column in the groupby and no operator, the user wants a groupby
- create another syntax
If we want to retrieve the unique values of a column, the best current syntax would be
?<col_name>__groupby, but it doesn't work as expected: without any aggregation operator in the query (likesumormean), the returned data only contains the value of thecol_namecolumn for each row, as they appear in the table.This can be explained as the Postgrest query is then
select=<col_name>, which only selects the values, without performing any additional operation, including a groupby. A current way to achieve a real groupby is to add an aggregation operation to the query.Example:
https://tabular-api.data.gouv.fr/api/resources/75a43900-a916-4105-adcf-fe88f88194a8/data/?inseecommuneprinc__isnotnull&inseecommuneprinc__groupby
yields
{ "data": [ { "inseecommuneprinc": "01007" }, { "inseecommuneprinc": "01007" }, { "inseecommuneprinc": "01007" }, { "inseecommuneprinc": "01007" }, { "inseecommuneprinc": "01007" }, { "inseecommuneprinc": "01006" }, ...whereas https://tabular-api.data.gouv.fr/api/resources/75a43900-a916-4105-adcf-fe88f88194a8/data/?inseecommuneprinc__isnotnull&inseecommuneprinc__groupby&annee__sum
yields
{ "data": [ { "inseecommuneprinc": "01001", "annee__sum": 58593 }, { "inseecommuneprinc": "01002", "annee__sum": 181913 }, { "inseecommuneprinc": "01004", "annee__sum": 1353962 }, { "inseecommuneprinc": "01005", "annee__sum": 131522 }, ...(without duplicates)
Possible solutions: