Description
Describe the bug
If a postgres function returns a record or a table row type, the generated return type is "unknonwn" which is incorrect.
To Reproduce
- Create a function which returns a record or a table row type.
- Generate types (supabase gen types typescript --project-id "<project_id>" --schema <schema_id> > supabase/types/supabase.ts")
Expected behavior
It should return the table row type or record type or as a workarround a value which is not "unknown". The return type "unknown" removes type safety but also complicates working with the returned data.
Code snippets
If I have a table
CREATE TABLE groups (
id uuid,
name text
);
and I create a function returning a record of that table
CREATE OR REPLACE FUNCTION read_group_record(group_id uuid)
RETURNS record
LANGUAGE plpgsql
AS $$
DECLARE
group_record record;
BEGIN
SELECT *
INTO group_record
FROM groups
WHERE id = group_id;
RETURN group_record;
END;
$$;
or a table row type of that table
CREATE FUNCTION read_group_table_row_type(group_id uuid)
RETURNS groups
LANGUAGE plpgsql
AS $$
DECLARE
group_record groups%ROWTYPE;
BEGIN
SELECT *
INTO group_record
FROM groups
WHERE id = group_id;
RETURN group_record;
END;
$$;
the generated types are:
read_group_record: {
Returns: Record<string, unknown>
}
read_group_table_row_type: {
Returns: unknown
}
But I would have expected something like
read_group_table_row_type: {
Returns: {
id: string
name: string
}
}
System information
- Version of OS: Windows 11
- Version of CLI: v1.163.6
- Version of Docker: Docker Desktop 4.24.2 (124339)
- Versions of services: [Generated types | Output command generate types]
Additional context
- Browser [e.g. edge, chrome]
PS: This is my first bug report. If you require more information, I am happy to provide them. If I should define the return types differently to use the type generation, please provide me an example and I will close the issue.