Skip to content

Commit 3518530

Browse files
authored
Quoted date string when fetching obserations (#1459)
This fixes a bug where requesting observations for a date that contains a hyphen (Example: `2024-09`) would return an empty result set. Before: ``` curl -XPOST "http://localhost:8080/core/api/v2/observation" -d ' { "select": [ "date", "value", "variable", "entity" ], "entity": { "expression": "country/USA<-containedInPlace+{typeOf:State}" }, "variable": { "dcids": [ "Count_SubsidizedHousingUnit" ] }, "date": "2023-12-31" } ' ``` Returns ``` {"byVariable":{"Count_SubsidizedHousingUnit":{}}} ``` After: Returns ``` {"byVariable":{"Count_SubsidizedHousingUnit":{"byEntity":{"geoId/40":{"orderedFacets":[{"facetId":"4243125145","observations":[{"date":"2023-12-31","value":53562}],"obsCount":1,"earliestDate":"2023-12-31","latestDate":"2023-12-31"}]},"geoId/41":{"orderedFacets":[{"facetId":"4243125145","observations":[{"date":"2023-12-31","value":57113}],"obsCount":1,"earliestDate":"2023-12-31","latestDate":"2023-12-31"}]},"geoId/02":{"orderedFacets":[{"facetId":"4243125145","observations":[{"date":"2023-12-31","value":7962}],"obsCount":1,"earliestDate":"2023-12-31","latestDate":"2023-12-31"}]}, ... }} ``` TODO: Add test cases
1 parent fdd6b39 commit 3518530

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

internal/sqldb/sqlquery/observation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ func getObservationsSQLQuery(variables []string,
199199
variablesStr,
200200
)
201201
if queryDate != "" && queryDate != shared.LATEST {
202-
query += fmt.Sprintf("AND date = (%s) ", queryDate)
202+
query += fmt.Sprintf("AND date = ('%s') ", queryDate)
203203
}
204204
query += "ORDER BY date ASC;"
205205
return query

0 commit comments

Comments
 (0)