Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type generation script does not pick up correct type when a SQL function returns data from other table #732

Closed
2 tasks done
travis-humata opened this issue Feb 29, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@travis-humata
Copy link

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

When we define SQL functions to return a value from another table they are typed as unknown instead of picking up the type from that table e.g.

CREATE OR REPLACE FUNCTION get_areas_for_semantic_chunks(_chunk_ids UUID[])
RETURNS TABLE (areas public.semantic_chunk_areas[]) AS $$
BEGIN
  RETURN QUERY
  SELECT array_agg(areas.* ORDER BY areas.text_start_index)
  FROM semantic_chunk_to_semantic_chunk_areas AS join_table
  JOIN semantic_chunk_areas AS areas
    ON join_table.chunk_area_id = areas.id
  WHERE join_table.chunk_id = ANY(_chunk_ids);
END;
$$ LANGUAGE plpgsql
SECURITY DEFINER;

generates type:

      get_areas_for_semantic_chunks: {
        Args: {
          _chunk_ids: string[]
        }
        Returns: {
          areas: unknown[]
        }[]
      }

whereas I would expect it to be:

      get_areas_for_semantic_chunks: {
        Args: {
          _chunk_ids: string[]
        }
        Returns: {
          areas: Database['public']['Tables']['semantic_chunk_areas']['Row']
        }[]
      }

To generate the types we are running this command:

npx supabase gen types typescript --project-id uokudzbrbkipvuxpkzhc --schema public > types/supabase.ts

To Reproduce

  1. Create a SQL function that returns a table with one of the columns of the return table being an item from another table in your schema
  2. Run the type genreration script
  3. Note that the type for that column will be unknown even though the type is known

See snippet above

Expected behavior

The generated type will match the type of the existing table

@travis-humata travis-humata added the bug Something isn't working label Feb 29, 2024
@soedirgo
Copy link
Member

Thanks! Resolved in #533, which has been deployed on the hosted platform & latest Supabase CLI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants