Search code examples
soqlsocratasoda

'in(..)' function not working in SoQL query


Using SoQL (Socrata Query Language) we can filter the values of a data set using the in(...) function. A sample example is shown in the socrata website using the Chicago open data portal.

https://data.cityofchicago.org/resource/6zsd-86xi.json?$where=primary_type in('THEFT', 'ROBBERY', 'INTIMIDATION')

But when I try this functionality using a different data set of the same data portal I don't get the answer. Here is the SoQL I used

https://data.cityofchicago.org/resource/uupf-x98q.json?$where=police_district in('12','24')

I get the following error.

{
  "code" : "query.compiler.malformed",
  "error" : true,
  "message" : "Error, could not parse SoQL query \"select * from #uupf-x98q where police_district in('12','24')\"",
  "data" : {
    "query" : "select * from #uupf-x98q where police_district in('12','24')"
  }
}

Solution

  • In the case of your second query, you're accessing it via a filtered view which limits some of the things you can do with that API endpoint. If you follow the link to the API Documentation for that dataset ("Export" -> "SODA API" -> "API Docs") it'll bring you to the dataset-level API docs where you'll have more success.

    For the first query, I'd recommend you migrate to it's new API endpoint, where you'll find performance to be a lot better. It should be as simple as swapping out the dataset identifier or base URL in your query.