fix: fix embedding through views with subqueries inside function calls

resolves #1608

Refactors the pfkSourceColumns query to use an intermediate JSON format
for parsing. This allows much more robust extraction of source columns.
This commit is contained in:
Wolfgang Walther
2020-12-10 19:48:05 +01:00
parent ebd474a7e6
commit 093fd3c8f6
4 changed files with 112 additions and 31 deletions
+6
View File
@@ -454,6 +454,12 @@ spec actualPgVersion = do
[json|[{"title":"1984","first_publisher":"Secker & Warburg","author":{"name":"George Orwell"}}]|]
{ matchHeaders = [matchContentTypeJson] }
it "works with views that have subselects in a function call" $
get "/authors_have_book_in_decade2?select=*,books(title)&id=eq.3"
`shouldRespondWith`
[json|[ {"id":3,"name":"Antoine de Saint-Exupéry","has_book_in_forties":true,"has_book_in_fifties":false,
"has_book_in_sixties":false,"books":[{"title":"The Little Prince"}]} ]|]
it "works with views that have CTE" $
get "/odd_years_publications?select=title,publication_year,first_publisher,author:authors(name)&id=in.(1,2,3)" `shouldRespondWith`
[json|[
+1
View File
@@ -96,6 +96,7 @@ GRANT ALL ON TABLE
, jsonb_test
, authors_books_number
, authors_have_book_in_decade
, authors_have_book_in_decade2
, forties_and_fifties_books
, odd_years_publications
, foos
+18
View File
@@ -1433,6 +1433,24 @@ select
end as has_book_in_sixties
from private.authors x;
create view test.authors_have_book_in_decade2 as
select
id,
name,
coalesce(
(select true from test.forties_books where author_id=x.id limit 1),
false
) as has_book_in_forties,
coalesce(
(select true from test.fifties_books where author_id=x.id limit 1),
false
) as has_book_in_fifties,
coalesce(
(select true from test.sixties_books where author_id=x.id limit 1),
false
) as has_book_in_sixties
from private.authors x;
create view test.forties_and_fifties_books as
select x.id, x.title, x.publication_year, y.name as first_publisher, x.author_id
from (