You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Typescript generation fail to generate type for custom type. #686
if I use a custom type as return of database function, i loose the typing .
To Reproduce
Create original function
CREATE OR REPLACEFUNCTIONpublic.get_total_stats(userid uuid, dateid character varying)
RETURNS TABLE(mau bigint, storage bigint, bandwidth bigint)
LANGUAGE plpgsql
SECURITY DEFINER
AS $function$
Begin
RETURN QUERY SELECTSUM(devices)::bigintAS mau,
SUM(version_size)::bigintAS storage,
SUM(app_stats.bandwidth)::bigintAS bandwidth
FROM app_stats
WHERE user_id = userid
AND date_id=dateid;
End;
$function$
Run the cli to get type declaration, you get this type declaration:
But i decided to create a custom type instead of repeat myself, in each function, like that:
CREATETYPEstats_tableAS (mau bigint, bandwidth double precision, storage double precision);
CREATE OR REPLACEFUNCTIONpublic.get_total_stats_v2(userid uuid, dateid character varying)
RETURNS stats_table
AS $function$
DECLARE
total stats_table;
BEGIN
RETURN SELECTSUM(devices)::bigintAS mau,
SUM(version_size)::bigintAS storage,
SUM(app_stats.bandwidth)::bigintAS bandwidth
FROM app_stats
WHERE user_id = userid
AND date_id=dateid into total;
RETURN total;
END;
$function$
LANGUAGE plpgsql
SECURITY DEFINER;
Expected behavior
I expect the CLI to create the same return type, since the SQL function return the same, but instead I got:
Activity
soedirgo commentedon Dec 13, 2022
Yeah, I think composite types are just
unknownright now. Will take a look in a bit.soedirgo commentedon Mar 14, 2024
Resolved in supabase/postgres-meta#459