© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago
talpiven

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' 
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$
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
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

RPC function return type is unknown
SupabaseSSupabase / help-and-questions
4y ago
Typescript return type for Functions
SupabaseSSupabase / help-and-questions
4y ago
Updated SQL function
SupabaseSSupabase / help-and-questions
4y ago
Help with SQL function
SupabaseSSupabase / help-and-questions
4y ago