Search code examples
socratasoda

Query with negative numbers not working as expected


I'm trying to write a query to this data set:

https://data.sfgov.org/City-Infrastructure/Street-Tree-List/tkzw-k3nq

I want to return the records that have a latitude AND longitude between certain values.

My attempt at a query string:

"https://data.sfgov.org/resource/2zah-tuvt.json?$limit=1000&$where=latitude between 37.709864 and 37.781918 AND longitude between -122.398942 and -122.501212"

The request limits the response to 1000 records and searches for records with a latitude between the specified numbers AND a longitude between the specified numbers.

The request does not produce an error but it also doesn't include any results. There are thousands of records that should satisfy the parameters and I'm not sure why I'm not getting a response.

When I test off of the latitude values only, the response returns as expected. When I test off of the longitude values only, I get no response. I've tested the longitude for values < 0 (since all of the longitude values are negative numbers) and that does produce a correct response.

I have a feeling the negative numbers I'm trying to search for are causing the issue. Is there some way to format the negative numbers so SoQL sees them as part of the search number instead of an operator? I've also tried wrapping the negative numbers in parentheses but that didn't help.

What do I need to change to get the response to return my desired results?


Solution

  • On a "between", the LOWER number needs to be on the left and the GREATER number on the right. Negative numbers obviously work the opposite (greatest absolute value actually belongs on the LEFT)

    change to

     between -122.501212 and -122.398942