Fix find_citizens SQL query

This commit is contained in:
2020-06-14 00:30:45 +02:00
parent e2d1b697b7
commit 63c4568aeb
2 changed files with 11 additions and 5 deletions

View File

@@ -9,8 +9,7 @@ create or replace function find_citizens(
) language plpgsql as
$$
begin
select json_agg(t), (select count(id) from citizen)
into resource, total
select json_agg(t) into resource
from (
select
z.*,
@@ -38,6 +37,13 @@ begin
z.created_at desc
limit "limit" offset "offset"
) as t;
select count(id) into total
from citizen
where "search" is null or (
(name->'first_name')::text ilike '%'||"search"||'%' or
(name->'last_name')::text ilike '%'||"search"||'%'
);
end;
$$;