Open psteinroe opened 5 months ago
Both schemas need to be in db-schemas
:
db-schemas = "api,public"
Then, the request would be:
curl 'localhost:3000/one?select=name,list:two(name)'
My expectation is that postgrest prefers the table in the primary schema.
I would expect so too. I had my doubts since PostgREST allows embedding through views and thought that maybe this is detecting public.one-two
and api.one-two
as possible intermediate embeds. But then I tried dropping the api.one_two
view, this would mean that public.one-two
is the only candidate to embed between api.one
and api.two
. As expected it recognized it, but it returned a SQL error:
{
"code": "42P01",
"details": null,
"hint": "There is an entry for table \"one_two\", but it cannot be referenced from this part of the query.",
"message": "invalid reference to FROM-clause entry for table \"one_two\""
}
So, there's definitely something wrong with a) the embedding detection or b) with building the query. I believe that it's both so I'm tagging this one as a bug for now.
For now, you can disambiguate the many-to-many relationships using spread embeds. So, the request would be:
curl 'localhost:3000/one?select=name,list:one_two(...two(name))'
Or, I'm assuming it's like this in supabase-js
:
const { data, error } = await s.from("one").select("name,list:one_two(...two(name))");
Thanks for the quick response!
Our use case is that the api schema will serve as our public api, and changing all queries in our app that target the public schema is not an option.
Let me know if I can support here further.
Our use case is that the api schema will serve as our public api,
Why is public
then part of db-schemas
?
You should only add the schema to be exposed as the api there. db-schemas=api
would be enough.
So, there's definitely something wrong with a) the embedding detection or b) with building the query. I believe that it's both
Agreed.
Why is
public
then part ofdb-schemas
?
because we are using the public
schema as our "internal" api used by our apps, and the api
schema for the public api used by our customers.
because we are using the public schema as our "internal" api used by our apps, and the api schema for the public api used by our customers.
Ah, interesting. You could also spin up two postgrest instances, one for each. This way you would be able to avoid dealing with all the Profile headers etc., too.
But ultimately, this is a bug, yes.
Environment
Description of issue
A Postgrest many-to-many query fails if a table in the "primary" schema has the same name as a view in another schema also exposed by postgrest.
My expectation is that postgrest prefers the table in the primary schema. Note that explicitly setting the db schema on the supabase client also does not change anything.
Reproduction: https://github.com/psteinroe/postgrest-repro
Schema:
The query (using supabase-js):