-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Null filtering on Embedded Resources bug #2800
Comments
ProblemIt looks like a bug. Here's a reproducible example: create table api.table2 (
field_b text primary key,
field_c text,
field_d text
);
create table api.table1 (
field_a text primary key ,
field_b text references api.table2(field_b)
);
insert into api.table2(field_b, field_c, field_d)
VALUES ('b1', 'c1', 'd1'),
('b2', 'c2', null);
insert into api.table1(field_a, field_b)
VALUES ('a1', 'b1'),
('a2', 'b2');
From your log: select * table1
left join lateral (
select * from table2
where id = table1.table2_id ) as "table1_table2_id" on true
where "table1_table2_id" is not null Looks like the where table1_table2_id.* is not null
-- or
where table1_table2_id.field_b is not null and table1_table2_id.field_c is not null and table1_table2_id.field_d is not null That's why it does not show rows that have null values in any of those columns. Also, this issue only happens with To-One relationships. When doing a To-Many embedding, it works as expected. WorkaroundThis is equivalent to an inner join, so, for now, keep using
SolutionThis part of the query needs to change to fix the issue:
Maybe adding the primary key in the filter or verifying if the row is null: where "table1_table2_id.field_b" is not null
-- or
where row_to_json(table1_table2_id.*) is not null |
@laurenceisla Thanks for the answer, |
This is how PostgreSQL behaves for
I'm not sure whether it makes sense for PostgREST to try to change how PostgreSQL behaves here. The query string filter However, I see that the PostgREST docs are describing it like this:
If that's the goal, then
In any case the difference (or similarity, depending on which approach is taken) between |
Yeah, I think we should do it like that. It's more intuitive for the API client and not much work for us too. |
After doing some tests, I checked that the curl "http://localhost:3000/table1?select=*,table2(*)&table2=not.is.null But if we select only one column that has a curl "http://localhost:3000/table1?select=*,table2(field_c)&table2=not.is.null Then the result will be the same as
|
Environment
Description of issue
Trying to use new feature : Null filtering on Embedded Resources
Table & Data :
Table1 :
Table2
doing :
GET /table1?select=*,table2(*)&table2=not.is.null
Result :
expected :
I'm not getting the second row because FieldD is null
it seems to be a problem from the postgresql's request,
here the one i got through the log : (simplified)
Any idea how i could get a workaround ?
any idea how i could bypass this problem ?
The text was updated successfully, but these errors were encountered: