CREATE OR REPLACE FUNCTION public.get_cards()
RETURNS TABLE(id bigint, updated_at timestamp with time zone, user_id uuid, name character varying, images_urls character varying[], description character varying, is_tradeable boolean, type smallint, favorites integer, views bigint)
LANGUAGE sql
AS $function$
select car.* , count(fav.collectible_id) as favorites, view.count as views
from cards car
join favorites fav on car.id=fav.collectible_id join views view on fav.collectible_id=view.collectible_id
where fav.collectible_type=1 and view.collectible_type=1
group by car.id , fav.collectible_id, view.count
LIMIT 20 OFFSET 0;
$function$
CREATE OR REPLACE FUNCTION public.get_cards()
RETURNS TABLE(id bigint, updated_at timestamp with time zone, user_id uuid, name character varying, images_urls character varying[], description character varying, is_tradeable boolean, type smallint, favorites integer, views bigint)
LANGUAGE sql
AS $function$
select car.* , count(fav.collectible_id) as favorites, view.count as views
from cards car
join favorites fav on car.id=fav.collectible_id join views view on fav.collectible_id=view.collectible_id
where fav.collectible_type=1 and view.collectible_type=1
group by car.id , fav.collectible_id, view.count
LIMIT 20 OFFSET 0;
$function$