Skip to content

Commit 01bad90

Browse files
authored
Merge pull request #260 from technologiestiftung/staging
feat: use included_in_map_layer flag for todays waterings (#259)
2 parents 7a05ddc + f5fee68 commit 01bad90

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
ALTER TABLE trees_watered ADD COLUMN included_in_map_layer BOOLEAN DEFAULT FALSE;
2+
3+
CREATE OR REPLACE FUNCTION public.watered_today()
4+
RETURNS TABLE(tree_id text, total_amount integer)
5+
LANGUAGE plpgsql
6+
SECURITY DEFINER
7+
AS $function$
8+
BEGIN
9+
RETURN query
10+
11+
WITH today_midnight AS (SELECT DATE_TRUNC('day', NOW()) AS midnight)
12+
SELECT
13+
trees_watered.tree_id as tree_id,
14+
SUM(amount)::integer AS total_amount
15+
FROM
16+
trees_watered
17+
WHERE
18+
timestamp >= (SELECT midnight FROM today_midnight) AND included_in_map_layer = FALSE
19+
GROUP BY
20+
trees_watered.tree_id;
21+
22+
END;
23+
$function$;

0 commit comments

Comments
 (0)