Describe the bug
Selecting a computed field on a table results in a TypeScript error:
// SelectQueryError<"column 'name_translated' does not exist on 'category'.">[] | null
const { data: data_computed_field } = await supabase
.from("category")
.select("name, name_translated");
Querying a computed relationship works as expected. See Steps to reproduce below and the linked MRE for further details.
Library affected
supabase-js
Reproduction
https://codesandbox.io/p/sandbox/89mt23
Steps to reproduce
- For a given table, create a Postgres function that accepts the table and returns a scalar, and thus can be used as a computed field in PostgREST; see example below
- Generate TS types, i.e. via CLI
- Initialize client via
createClient<Database>(/* ... */)
- Query computed field => SelectQueryError
Computed fields vs computed relationships
Computed relationships work as expected; see the linked MRE. This is the case because they are added explicitly as functions and also in Database['public']['your_table_name']['Row'] whereas there is no entry for computed fields (^= functions returning a scalar).
Adding the missing computed field name during generation (or for now: manually) fixes the issue, but I cannot tell if this is the ideal solution or if anything speaks against it.
Special case
In my specific case, separate name_translated functions exists for two tables, resulting in a generated TS type like this:
name_translated:
| {
Args: { category: Database['public']['Tables']['category']['Row'] }
Returns: string
}
| {
Args: { something_else: Database['public']['Tables']['something_else']['Row'] }
Returns: string
}
Using different function/field names does not prevent the issue, but a fix may need to take the possibility of identical function/field names into consideration.
Postgres function example
CREATE OR REPLACE FUNCTION name_translated(category category)
RETURNS text
LANGUAGE sql
STABLE
AS $$
-- ... actual logic omitted ...
$$;
System Info
Reproducible on arbitrary system; tested on Codesandbox, Linux, MacOS
Supabase CLI v2.67.1
supabase-js v2.89.0
TypeScript v5.5.4
Used Package Manager
bun
Logs
No response
Validations
Describe the bug
Selecting a computed field on a table results in a TypeScript error:
Querying a computed relationship works as expected. See Steps to reproduce below and the linked MRE for further details.
Library affected
supabase-js
Reproduction
https://codesandbox.io/p/sandbox/89mt23
Steps to reproduce
createClient<Database>(/* ... */)Computed fields vs computed relationships
Computed relationships work as expected; see the linked MRE. This is the case because they are added explicitly as functions and also in
Database['public']['your_table_name']['Row']whereas there is no entry for computed fields (^= functions returning a scalar).Adding the missing computed field name during generation (or for now: manually) fixes the issue, but I cannot tell if this is the ideal solution or if anything speaks against it.
Special case
In my specific case, separate
name_translatedfunctions exists for two tables, resulting in a generated TS type like this:name_translated: | { Args: { category: Database['public']['Tables']['category']['Row'] } Returns: string } | { Args: { something_else: Database['public']['Tables']['something_else']['Row'] } Returns: string }Using different function/field names does not prevent the issue, but a fix may need to take the possibility of identical function/field names into consideration.
Postgres function example
System Info
Reproducible on arbitrary system; tested on Codesandbox, Linux, MacOS Supabase CLI v2.67.1 supabase-js v2.89.0 TypeScript v5.5.4Used Package Manager
bun
Logs
No response
Validations