Skip to content

Commit

Permalink
Merge pull request #260 from technologiestiftung/staging
Browse files Browse the repository at this point in the history
feat: use included_in_map_layer flag for todays waterings (#259)
  • Loading branch information
Jaszkowic authored May 28, 2024
2 parents 7a05ddc + f5fee68 commit 01bad90
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ALTER TABLE trees_watered ADD COLUMN included_in_map_layer BOOLEAN DEFAULT FALSE;

CREATE OR REPLACE FUNCTION public.watered_today()
RETURNS TABLE(tree_id text, total_amount integer)
LANGUAGE plpgsql
SECURITY DEFINER
AS $function$
BEGIN
RETURN query

WITH today_midnight AS (SELECT DATE_TRUNC('day', NOW()) AS midnight)
SELECT
trees_watered.tree_id as tree_id,
SUM(amount)::integer AS total_amount
FROM
trees_watered
WHERE
timestamp >= (SELECT midnight FROM today_midnight) AND included_in_map_layer = FALSE
GROUP BY
trees_watered.tree_id;

END;
$function$;

0 comments on commit 01bad90

Please sign in to comment.