diff --git a/test/spec/Feature/Query/RelatedQueriesSpec.hs b/test/spec/Feature/Query/RelatedQueriesSpec.hs index 0db178cf9d..bd25a91577 100644 --- a/test/spec/Feature/Query/RelatedQueriesSpec.hs +++ b/test/spec/Feature/Query/RelatedQueriesSpec.hs @@ -256,3 +256,15 @@ spec = describe "related queries" $ do { matchStatus = 200 , matchHeaders = [matchContentTypeJson] } + + -- "?table=not.is.null" does a "NOT table IS NULL" instead of a "table IS NOT NULL" + -- https://github.com/PostgREST/postgrest/issues/2800#issuecomment-1562620508 + it "embeds even if the target relationship has a row with a NULL value in any of its columns" $ + get "/table_b?select=name,table_a(name)&table_a=not.is.null" `shouldRespondWith` + [json|[ + {"name":"Test 1","table_a":{"name":"Not null"}}, + {"name":"Test 2","table_a":{"name":null}} + ]|] + { matchStatus = 200 + , matchHeaders = [matchContentTypeJson] + } diff --git a/test/spec/fixtures/data.sql b/test/spec/fixtures/data.sql index a2ba2e24fc..1d54d14bcb 100644 --- a/test/spec/fixtures/data.sql +++ b/test/spec/fixtures/data.sql @@ -853,3 +853,8 @@ INSERT INTO datarep_next_two_todos VALUES (2, 1, 3, 'do these first'); TRUNCATE TABLE bitchar_with_length CASCADE; INSERT INTO bitchar_with_length(bit, char) VALUES ('00000', 'aaaaa'); INSERT INTO bitchar_with_length(bit, char) VALUES ('11111', 'bbbbb'); + +TRUNCATE TABLE table_a CASCADE; +INSERT INTO table_a(id, name) VALUES (1, 'Not null'), (2, null); +TRUNCATE TABLE table_b CASCADE; +INSERT INTO table_b(table_a_id, name) VALUES (1, 'Test 1'), (2, 'Test 2'); diff --git a/test/spec/fixtures/schema.sql b/test/spec/fixtures/schema.sql index f01b5efb20..9a0fa2fd74 100644 --- a/test/spec/fixtures/schema.sql +++ b/test/spec/fixtures/schema.sql @@ -3437,3 +3437,13 @@ begin message = '{"code":"123","message":"ABC","details":"DEF"}'; end $$; + +create table table_a ( + id int primary key, + name text +); + +create table table_b ( + table_a_id int references table_a(id), + name text +);