Skip to content

Typescript generation fail to generate type for custom type. #686

Closed

Description

@riderx

Bug report

Describe the bug

if I use a custom type as return of database function, i loose the typing .

To Reproduce

Create original function

CREATE OR REPLACE FUNCTION public.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 SELECT 
    SUM(devices)::bigint AS mau,
    SUM(version_size)::bigint AS storage,
    SUM(app_stats.bandwidth)::bigint AS 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:

{
      get_total_stats: {
        Args: { userid: string; dateid: string }
        Returns: { mau: number; storage: number; bandwidth: number }[]
      }
}

But i decided to create a custom type instead of repeat myself, in each function, like that:

CREATE TYPE stats_table AS (mau bigint, bandwidth double precision, storage double precision);

CREATE OR REPLACE FUNCTION public.get_total_stats_v2(userid uuid, dateid character varying)
RETURNS stats_table
AS $function$
  DECLARE
      total stats_table;
  BEGIN
    RETURN SELECT 
      SUM(devices)::bigint AS mau,
      SUM(version_size)::bigint AS storage,
      SUM(app_stats.bandwidth)::bigint AS 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:

      get_total_stats_v2: {
        Args: { userid: string; dateid: string }
        Returns: unknown
      }

System information

  • OS: macOS
  • Browser Brave
  • Version of supabase-js: 2.1.2
  • Version of Node.js: 18

Activity

  1. added
    bug
    on Dec 12, 2022
  2. soedirgo commented on Dec 13, 2022

    @soedirgo
    Member

    Yeah, I think composite types are just unknown right now. Will take a look in a bit.

  3. soedirgo commented on Mar 14, 2024

    @soedirgo
    Member
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions