This requires a bunch of changes since the types on these tables are much closer to the underlying types of the Fieldseeker data we are getting back from the API. I now need to use proper UUID types everywhere, which means I had to modify the bob gen config to consistently use google UUID, my UUID library of choice. I also had to add the organization_id to all the fieldseeker tables since we rely on them existing for some of our compound queries. There were some changes to the API type signatures to get things to build. I may yet regret those.
12 lines
331 B
SQL
12 lines
331 B
SQL
-- TrapDataByLocationIDRecent
|
|
SELECT enddatetime, globalid, loc_id
|
|
FROM (
|
|
SELECT enddatetime, globalid, loc_id, ROW_NUMBER()
|
|
OVER (PARTITION BY loc_id ORDER BY enddatetime DESC) as row_num
|
|
FROM fieldseeker.trapdata
|
|
WHERE
|
|
organization_id = $1 AND
|
|
loc_id IN ($2)
|
|
) ranked_data
|
|
WHERE row_num <= 10
|
|
ORDER BY enddatetime DESC;
|