Our application stores a table called partners. Since our partners can be either individual or legal persons, and we store different data for each of these two types of partners, we created two new tables: indiv_partners and legal_partners.
The primary key of partners is id, while the primary keys of indiv_partners and legal_partners are both called id_partner and reference the id column of partners.
We would like to write a query that retrieves the names of all the partners. That is, if the current partner is an individual, then we want its first_name and last_name fields. However, if it is a legal person, then we just want its name field. Thus, we start with the following code:
Bug report
Context
Our application stores a table called
partners
. Since our partners can be either individual or legal persons, and we store different data for each of these two types of partners, we created two new tables:indiv_partners
andlegal_partners
.The primary key of
partners
isid
, while the primary keys ofindiv_partners
andlegal_partners
are both calledid_partner
and reference theid
column ofpartners
.We would like to write a query that retrieves the names of all the partners. That is, if the current partner is an individual, then we want its
first_name
andlast_name
fields. However, if it is a legal person, then we just want itsname
field. Thus, we start with the following code:Bug description
The problem is that the type of
data
gets inferred incorrectly as:Expected behavior
The right type should be:
This is confirmed by the fact that Supabase actually returns an object of this shape (according to my tests).
Screenshots
The wrong type inference: