       'resourceType', 'Bundle',
       'totalResults', count(e.*),
       'updated', now(),
-      'entry', json_agg(e.*)
-    )::jsonb
-    FROM entry e
-    GROUP BY e.id
-
+      'entry', COALESCE(json_agg(e.*), '[]'::json)
+    )::jsonb
+    FROM entry e;
 $$;
 COMMENT ON FUNCTION fhir_history(_cfg jsonb, _type_ varchar, _id_ uuid, _params_ jsonb)
 IS 'Retrieve the changes history for a particular resource with logical id (_id_)\nReturn bundle with entries representing versions';

      'resourceType', 'Bundle',
      'totalResults', count(e.*),
      'updated', now(),
      'entry', json_agg(e.*)
    )::jsonb
    FROM entry e
    GROUP BY e.id
$$;
COMMENT ON FUNCTION fhir_history(_cfg jsonb, _params_ jsonb)
IS 'Retrieve the update history for all resources\nReturn bundle with entries representing versions';

      'resourceType', 'Bundle',
      'totalResults', count(e.*),
      'updated', now(),
      'entry', COALESCE(json_agg(e.*), '[]'::json)
    )::jsonb
    FROM entry e;
$$;
COMMENT ON FUNCTION fhir_history(_cfg jsonb, _type_ varchar, _params_ jsonb)
IS 'Retrieve the update history for a particular resource type\nReturn bundle with entries representing versions';
