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

Postgrest composite type casting error

Open Torres1080 opened this issue 2 years 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

After creating a clone of my own project I found a problem after executing some functions which relies on a postgrest rpc call. The function itself returns a composite type with the following parameters

create type tp_minified_application as (
  id bigint,
  assembler tp_company
);

where tp_company has the following implementation

create type tp_company as (
  id text,
  owner text
);

The function barely makes a simple select * from a table application and returns a set of tp_minified_application.I've tested it and it works fine.

create or replace function browse_minified_applications()
returns setof tp_minified_application as
$browse_minified_applications$
  select A.id, C assembler
  from application A
  join company C on C.id = A.assembler
$browse_minified_applications$ language sql;

The problem I'm facing is that when I make the call within my code

supabase.rpc("browse_minified_applications").eq("assembler->>id", '<any_id>'),

I get this error

operator does not exist: tp_company->> unknown

This could be it but on the other project I have with the exact same code It's working perfectly as it is on the example.

To Reproduce

Just creating the types and a simple function should work

Expected behavior

Whenever I make this query it should work and give correct results filtered by the company I'm asking.

System information

  • OS: Windows
  • Version of supabase-js: 2.33.1
  • Version of Node.js: 19.3.0

Additional context

Thanks in advance

Torres1080 avatar Sep 05 '23 16:09 Torres1080

I found out that creating an explicit cast between my type and JSON solves the problem, but I'm wondering if there's any other less complicated workaround with the same effect



create cast (tp_company as json) with function to_json as implicit;

Torres1080 avatar Sep 05 '23 20:09 Torres1080

@Torres1080 Hm, this should work normally, could you try the example on:

https://postgrest.org/en/stable/references/api/tables_views.html#composite-array-columns

steve-chavez avatar Sep 05 '23 20:09 steve-chavez

@steve-chavez I did some debugging with my two projects, and the queries I found that are being made under the hood are the following

image

As you can appreciate on the left picture (the new project with the bug), there's no such to_jsonb call, while on the right picture (the old project), to_jsonb It's being called—I don't know why actually.

Torres1080 avatar Sep 05 '23 20:09 Torres1080

@Torres1080 Can you compare both projects PostgREST versions?

You can get it from the https://<project_ref>.supabase.co/rest/v1 endpoints. There should be an OpenAPI json output with a version field there.

steve-chavez avatar Sep 06 '23 15:09 steve-chavez

@steve-chavez 11.2 (not working) vs 11.1 (working)

image

Torres1080 avatar Sep 06 '23 18:09 Torres1080

@Torres1080 Thanks for the report. We're going to fix this on https://github.com/PostgREST/postgrest/issues/2929.

steve-chavez avatar Sep 08 '23 17:09 steve-chavez

@steve-chavez You're welcome 👍

Torres1080 avatar Sep 08 '23 17:09 Torres1080

Closing this as it's already fixed in the latest PostgREST release.

soedirgo avatar May 28 '24 07:05 soedirgo