Fix #1242, embed a view having a select in a where
This commit is contained in:
committed by
Steve Chávez
parent
7c376d6e84
commit
1f513f24a5
@@ -13,6 +13,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
- #1223, Fix incorrect OpenAPI externalDocs url - @steve-chavez
|
||||
- #1221, Fix embedding other resources when having a self join - @steve-chavez
|
||||
- #1242, Fix embedding a view having a select in a where - @steve-chavez
|
||||
|
||||
## [5.2.0] - 2018-12-12
|
||||
|
||||
|
||||
@@ -707,8 +707,11 @@ allSynonyms cols pgVer =
|
||||
-- query explanation at https://gist.github.com/steve-chavez/7ee0e6590cddafb532e5f00c46275569
|
||||
where
|
||||
subselectRegex :: Text
|
||||
subselectRegex | pgVer < pgVersion100 = ":subselect {.*?:constraintDeps <>} :location"
|
||||
| otherwise = ":subselect {.*?:stmt_len 0} :location"
|
||||
-- "result" appears when the subselect is used inside "case when", see `authors_have_book_in_decade` fixture
|
||||
-- "resno" appears in every other case
|
||||
-- when copying the query into pg make sure you omit one backslash from \\d+, it should be like `\d+` for the regex
|
||||
subselectRegex | pgVer < pgVersion100 = ":subselect {.*?:constraintDeps <>} :location \\d+} :res(no|ult)"
|
||||
| otherwise = ":subselect {.*?:stmt_len 0} :location \\d+} :res(no|ult)"
|
||||
sql = [qc|
|
||||
with
|
||||
views as (
|
||||
|
||||
@@ -433,6 +433,11 @@ spec = do
|
||||
{"number_of_projects":2,"client":{"name":"Apple"}}] |]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
it "can embed a view that has a subselect containing a select in a where" $
|
||||
get "/authors_w_entities?select=name,entities,books(title)&id=eq.1" `shouldRespondWith`
|
||||
[json| [{"name":"George Orwell","entities":[3, 4],"books":[{"title":"1984"}]}] |]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
describe "path fixed" $ do
|
||||
it "works when requesting children 2 levels" $
|
||||
get "/clients?id=eq.1&select=id,projects:projects.client_id(id,tasks(id))" `shouldRespondWith`
|
||||
|
||||
Vendored
+1
@@ -99,6 +99,7 @@ GRANT ALL ON TABLE
|
||||
, projects_count_grouped_by
|
||||
, "Server Today"
|
||||
, pgrst_reserved_chars
|
||||
, authors_w_entities
|
||||
TO postgrest_test_anonymous;
|
||||
|
||||
GRANT INSERT ON TABLE insertonly TO postgrest_test_anonymous;
|
||||
|
||||
Vendored
+13
@@ -1545,6 +1545,19 @@ select
|
||||
from projects
|
||||
group by client_id;
|
||||
|
||||
create view test.authors_w_entities as
|
||||
select
|
||||
id,
|
||||
name,
|
||||
(
|
||||
select json_agg(id)
|
||||
from test.entities
|
||||
where id not in (
|
||||
select parent_id from test.child_entities
|
||||
)
|
||||
) as entities
|
||||
from private.authors;
|
||||
|
||||
CREATE TABLE test."Foo"(
|
||||
id int primary key,
|
||||
name text
|
||||
|
||||
Reference in New Issue
Block a user