Fix RPC return type handling for domains with composite base type
This commit is contained in:
committed by
Steve Chavez
parent
3f690ec78f
commit
ca7ffd0a70
@@ -197,6 +197,16 @@ spec actualPgVersion =
|
||||
]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
when (actualPgVersion >= pgVersion110) $
|
||||
it "can embed if rpc returns domain of table type" $ do
|
||||
post "/rpc/getproject_domain?select=id,name,client:clients(id),tasks(id)"
|
||||
[json| { "id": 1} |]
|
||||
`shouldRespondWith`
|
||||
[json|[{"id":1,"name":"Windows 7","client":{"id":1},"tasks":[{"id":1},{"id":2}]}]|]
|
||||
get "/rpc/getproject_domain?id=1&select=id,name,client:clients(id),tasks(id)"
|
||||
`shouldRespondWith`
|
||||
[json|[{"id":1,"name":"Windows 7","client":{"id":1},"tasks":[{"id":1},{"id":2}]}]|]
|
||||
|
||||
context "a proc that returns an empty rowset" $
|
||||
it "returns empty json array" $ do
|
||||
post "/rpc/test_empty_rowset" [json| {} |] `shouldRespondWith`
|
||||
@@ -258,6 +268,12 @@ spec actualPgVersion =
|
||||
it "cannot return composite type in hidden schema" $
|
||||
post "/rpc/ret_point_3d" [json|{}|] `shouldRespondWith` 401
|
||||
|
||||
when (actualPgVersion >= pgVersion110) $
|
||||
it "returns domain of composite type" $
|
||||
post "/rpc/ret_composite_domain" [json|{}|] `shouldRespondWith`
|
||||
[json|[{"x": 10, "y": 5}]|]
|
||||
{ matchHeaders = [matchContentTypeJson] }
|
||||
|
||||
it "returns single row from table" $
|
||||
post "/rpc/single_article?select=id" [json|{"id": 2}|] `shouldRespondWith`
|
||||
[json|[{"id": 2}]|]
|
||||
|
||||
Vendored
+24
@@ -925,6 +925,19 @@ CREATE FUNCTION setprojects(id_l int, id_h int, name text) RETURNS SETOF project
|
||||
update test.projects set name = $3 WHERE id >= $1 AND id <= $2 returning *;
|
||||
$_$;
|
||||
|
||||
-- domains on tables are only supported from pg 11 on
|
||||
DO $do$BEGIN
|
||||
IF (SELECT current_setting('server_version_num')::INT >= 110000) THEN
|
||||
CREATE DOMAIN projects_domain AS projects;
|
||||
|
||||
CREATE FUNCTION getproject_domain(id int) RETURNS SETOF projects_domain
|
||||
LANGUAGE sql
|
||||
AS $_$
|
||||
SELECT projects::projects_domain FROM test.projects WHERE id = $1;
|
||||
$_$;
|
||||
END IF;
|
||||
END$do$;
|
||||
|
||||
create table images (
|
||||
name text not null,
|
||||
img bytea not null
|
||||
@@ -970,6 +983,17 @@ create function test.ret_point_2d() returns test.point_2d as $$
|
||||
select row(10, 5)::test.point_2d;
|
||||
$$ language sql;
|
||||
|
||||
-- domains on composite types are only supported from pg 11 on
|
||||
do $do$begin
|
||||
if (SELECT current_setting('server_version_num')::int >= 110000) then
|
||||
create domain test.composite_domain as test.point_2d;
|
||||
|
||||
create function test.ret_composite_domain() returns test.composite_domain as $$
|
||||
select row(10, 5)::test.composite_domain;
|
||||
$$ language sql;
|
||||
end if;
|
||||
end$do$;
|
||||
|
||||
create type private.point_3d as (x integer, y integer, z integer);
|
||||
|
||||
create function test.ret_point_3d() returns private.point_3d as $$
|
||||
|
||||
Reference in New Issue
Block a user