feature #7: add query "find_comments_by_citizen"

This commit is contained in:
2019-08-26 00:41:30 +02:00
parent d911109cd2
commit f167cf02f9
2 changed files with 37 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
create or replace function find_comments_by_citizen(
_citizen_id uuid,
"limit" int default 50,
"offset" int default 0,
out resource json,
out total int
) language plpgsql as
$$
begin
select json_agg(t), (select count(id) from "comment")
into resource, total
from (
select
com.*,
json_build_object('id', com.target_id) as target,
find_citizen_by_id(com.citizen_id) as citizen
from "comment" as com
where citizen_id = _citizen_id
order by created_at desc,
com.created_at desc
limit "limit" offset "offset"
) as t;
end;
$$;
-- drop function if exists find_comments_by_citizen(uuid, int, int);