postgrest-js icon indicating copy to clipboard operation
postgrest-js copied to clipboard

Error after upgrading to v2.33.1: SelectQueryError<"Referencing missing column `computed_review_score`">

Open whollacsek opened this issue 1 year ago • 7 comments

Bug report

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

Describe the bug

Error after upgrading to 2.33.1 I'm getting this Typescript error: SelectQueryError<"Referencing missing column 'computed_review_score'">

computed_review_score is a function:

CREATE FUNCTION computed_review_score(event event_ticketing.events) RETURNS numeric
    LANGUAGE sql AS
$$
SELECT COALESCE(event.review_score,
                (SELECT ROUND(AVG((VALUE ->> 'score')::NUMERIC), 1) FROM JSONB_ARRAY_ELEMENTS(event.reviews)));
$$;

And this is the query:

supabaseClient
    .rpc('search_events', payload)
    .select(
      '*, computed_review_score'
    )

Also it is strange that the generated type for this function has unknown for the argument, it should be the table type:

...
    Functions: {
      computed_review_score: {
        Args: {
          event: unknown
        }
        Returns: number
      }
    }
...

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Go to '…'
  2. Click on '…'
  3. Scroll down to '…'
  4. See error

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

System information

  • OS: [e.g. macOS, Windows]
  • Browser (if applies) [e.g. chrome, safari]
  • Version of supabase-js: [e.g. 6.0.2]
  • Version of Node.js: [e.g. 10.10.0]

Additional context

Add any other context about the problem here.

whollacsek avatar Aug 31 '23 18:08 whollacsek

Same issue here, broke my entire codebase.

I'm rolled back to an older version that supports computed columns:

"@supabase/postgrest-js": "=1.2.0"
"@supabase/supabase-js": "=2.4.0"

Sadly these version has issues with .maybeSingle(), see https://github.com/supabase/postgrest-js/issues/361

lopezjurip avatar Feb 06 '24 16:02 lopezjurip

I'm experiencing the same problem with supabase-js 2.39.8 and [email protected].

d-e-h-i-o avatar Mar 18 '24 09:03 d-e-h-i-o

I'm experiencing the same problem with supabase-js 2.39.8 and [email protected].

Im having the same issue! Same version notificationFrom: string & SelectQueryError<"Referencing missing column email">[];

But when I console log it, the object exists

AlexisKenAlvarez avatar Mar 18 '24 13:03 AlexisKenAlvarez

Similar problem with supabase-js 2.42.4 and postgrest-js 1.15.2 and updated TypeScript types:

const { data, error } = await supabase.from('category')
    .select('*, parent_category(id, name, color)')

// parent_category: SelectQueryError<"Referencing missing column `color`">[]
// or whatever column is mentioned last in the query

parent_category is set up as a function according to PostgREST docs.

stefan-girlich avatar Apr 18 '24 08:04 stefan-girlich

having the same issues as what everyone else is mentioning. i am using [email protected] and [email protected].

is Supabase not able to parse PostgREST syntax that contains computed columns/computed fields correctly in TypeScript?

SelectQueryError<"Referencing missing column `session_count`">

zineanteoh avatar Jun 03 '24 21:06 zineanteoh

I am getting the same error, but when querying a table and joining to the same secondary table twice.

With the following tables:


create table country (
    id bigint generated by default as identity,
    code text not null
  );

create table trip (
    origin_id bigint not null,
    destination_id bigint not null,
    constraint trip_origin_id_fkey foreign key (origin_id) references country (id),
    constraint trip_destination_id_fkey foreign key (destination_id) references country (id),
  );

and access as such


function fetchTrip(tripId: number) {
  return supabase.from("trip").select(`
      id
      origin:origin_id ( code ),
      destination:destination_id ( code )
      `).eq(
      "id",
      tripId,
    ).single()
}

In the browser I can see that this returns, for a randomly selected trip.

{
    "id": 1,
    "origin": {
        "code": "AU",
    },
    "destination": {
        "code": "US"
    }
}

But if try to type the return type of fetchShipment then I get errors like Property 'code' is missing in type 'SelectQueryError<"Referencing missing column code">[]'

JonNorman avatar Jun 17 '24 13:06 JonNorman