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

Postgrest composite type casting error #475

Closed
2 tasks done
Torres1080 opened this issue Sep 5, 2023 · 8 comments
Closed
2 tasks done

Postgrest composite type casting error #475

Torres1080 opened this issue Sep 5, 2023 · 8 comments
Labels
bug Something isn't working postgrest-patch-needed Requires a change on PostgREST

Comments

@Torres1080
Copy link

Torres1080 commented Sep 5, 2023

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

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 Torres1080 added the bug Something isn't working label Sep 5, 2023
@Torres1080
Copy link
Author

Torres1080 commented Sep 5, 2023

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;

@steve-chavez
Copy link
Member

@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

@Torres1080
Copy link
Author

Torres1080 commented Sep 5, 2023

@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.

@steve-chavez
Copy link
Member

@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.

@Torres1080
Copy link
Author

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

image

@steve-chavez
Copy link
Member

@Torres1080 Thanks for the report. We're going to fix this on PostgREST/postgrest#2929.

@steve-chavez steve-chavez added the postgrest-patch-needed Requires a change on PostgREST label Sep 8, 2023
@Torres1080
Copy link
Author

@steve-chavez You're welcome 👍

@soedirgo
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working postgrest-patch-needed Requires a change on PostgREST
Projects
None yet
Development

No branches or pull requests

3 participants