Where clause on join not working, shouldn't return rows but still does
Hello guys,
I have 2 tables with a join to link them together.
typically
Table 1
id
name
table_2_id
Table 2
id
name
type
In sql, if I wanted to return the row from table 1, where the type in table 2 is specific, I would just do:
select * from table1 join table2 on table2.id = table1.table_2_id where table2.type = 'form_supa'
I expect it to return nothing as the type is set as something else. In pure SQL,it works exactly as expected.
With supabase client, I tried ton use the .match("table2.type", 'form_supa')...but all it does is just not return the matches between table 1 and table 2...but still return the table1 entries.
How do you enforce the WHERE on join and inner join with the supabase client ?
Thanks in advance for the help
7 Replies
The supabase client really does inner joins with json. So your equivalent is:
Would be something like this:
or something similar
J
@jdgamble555 , That was the issue. Supabase ignores convention of SQL and the join isn't an inner join by default. Very silly of Supabase, but it's sorted at least.
Thanks for the help
You need to use !inner in your select, but Discord may be eating some of your code you are showing.
@garyaustin , yes that was the issue. But as I mentioned, SQL default is inner, so it's very awkward Supabase choose to go against SQL default convention for joins....
apparently they do it they way
postgrest
to be able to exclude top row items - https://postgrest.org/en/stable/releases/v9.0.0.html?highlight=inner%20join#resource-embedding-with-top-level-filtering - to me it makes more sense because it is like a graphHmm I disagree they do it postgrest, if I do a raw query in Supabase UI, it works as expected without any need for using inner join.
So it looks more like the client or engine behind it , used via the nodejs client is not on part with default convention
That's why I was very confused on why the raw query in Supabase UI works fine, but the conversion with Supabase client doesn't
Don’t confuse PostgREST the database API Supabase uses and Postgres the database you are accessing directly with SQL in the UI.
PostgREST.org.