Skip to content

Commit 79a00ab

Browse files
author
Espen Gulbrandsen
committed
Fix allow date filter comparison on time aspect
1 parent c32845a commit 79a00ab

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
CREATE OR REPLACE FUNCTION events.getappevents_v2(
2+
_subject character varying,
3+
_after character varying,
4+
_from timestamp with time zone,
5+
_to timestamp with time zone,
6+
_type text[],
7+
_source text[],
8+
_resource text,
9+
_size integer)
10+
RETURNS TABLE(cloudevents text)
11+
LANGUAGE 'plpgsql'
12+
COST 100
13+
VOLATILE PARALLEL UNSAFE
14+
ROWS 1000
15+
16+
AS $BODY$
17+
18+
DECLARE
19+
_sequenceno_first bigint;
20+
_sequenceno_last bigint;
21+
BEGIN
22+
23+
IF _after IS NOT NULL AND _after <> '' THEN
24+
SELECT
25+
case count(*)
26+
when 0
27+
then 0
28+
else
29+
(SELECT MIN(sequenceno)
30+
FROM events.events
31+
WHERE cloudevent->>'id' = _after)
32+
end
33+
INTO _sequenceno_first
34+
FROM events.events
35+
WHERE cloudevent->>'id' = _after;
36+
END IF;
37+
SELECT MAX(sequenceno) INTO _sequenceno_last FROM events.events WHERE registeredtime <= now() - interval '30 second';
38+
return query
39+
SELECT cast(cloudevent as text) as cloudevents
40+
FROM events.events
41+
WHERE (_subject IS NULL OR cloudevent->>'subject' = _subject)
42+
AND (_from IS NULL OR (cloudevent->>'time')::timestamptz >= _from)
43+
AND (_to IS NULL OR (cloudevent->>'time')::timestamptz <= _to)
44+
AND (_type IS NULL OR cloudevent->>'type' ILIKE ANY(_type))
45+
AND (_source IS NULL OR cloudevent->>'source' ILIKE ANY(_source))
46+
AND (_resource IS NULL OR cloudevent->>'resource' = _resource)
47+
AND (_after IS NULL OR _after = '' OR sequenceno > _sequenceno_first)
48+
AND (_sequenceno_last IS NULL OR sequenceno <= _sequenceno_last)
49+
ORDER BY sequenceno
50+
limit _size;
51+
END;
52+
$BODY$;

0 commit comments

Comments
 (0)