postgrest-js
postgrest-js copied to clipboard
Postgrest composite type casting error
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
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 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 I did some debugging with my two projects, and the queries I found that are being made under the hood are the following
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 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 11.2 (not working) vs 11.1 (working)
@Torres1080 Thanks for the report. We're going to fix this on https://github.com/PostgREST/postgrest/issues/2929.
@steve-chavez You're welcome 👍
Closing this as it's already fixed in the latest PostgREST release.