-
-
Notifications
You must be signed in to change notification settings - Fork 192
supabase-js: Selecting computed text field results in SelectQueryError #1034
Description
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.4Used Package Manager
bun
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Supabase JS Library issue and not an issue with the Supabase platform. If it's a Supabase platform related bug, it should likely be reported to supabase/supabase instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.