Set complex return type = SQL function

Cannot figure out how to define the return type , I dont understand how to debug + get the right types, if I copy paste the types from it still does not work.
Failed to run sql query: return type mismatch in function declared to return record


select COLUMN_NAME, data_type from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'cards'

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$
cards_table.png
views_table.png
Was this page helpful?