fix: Void functions return null instead of empty body (#1795)

* Change empty body reponse to null for scalar functions returning void or null values

* Add test for functions returning an integer with null value

Co-authored-by: Laurence Isla <lau.isla.c@gmail.com>
This commit is contained in:
laurenceisla
2021-04-08 01:45:13 +02:00
committed by GitHub
co-authored by Laurence Isla
parent 9c79a4174c
commit 7f11c1a991
3 changed files with 15 additions and 4 deletions
+1 -1
View File
@@ -98,7 +98,7 @@ asJsonF returnsScalar
asJsonSingleF :: Bool -> SqlFragment --TODO! unsafe when the query actually returns multiple rows, used only on inserting and returning single element
asJsonSingleF returnsScalar
| returnsScalar = "coalesce(string_agg(to_json(_postgrest_t.pgrst_scalar)::text, ','), '')::character varying"
| returnsScalar = "coalesce(string_agg(to_json(_postgrest_t.pgrst_scalar)::text, ','), 'null')::character varying"
| otherwise = "coalesce(string_agg(to_json(_postgrest_t)::text, ','), '')::character varying"
asBinaryF :: FieldName -> SqlFragment
+10 -3
View File
@@ -282,11 +282,18 @@ spec actualPgVersion =
`shouldRespondWith`
[json|{"id": 2}|]
it "returns nothing for void" $
it "returns null for void" $
post "/rpc/ret_void"
[json|{}|]
`shouldRespondWith`
""
"null"
{ matchHeaders = [matchContentTypeJson] }
it "returns null for an integer with null value" $
post "/rpc/ret_null"
[json|{}|]
`shouldRespondWith`
"null"
{ matchHeaders = [matchContentTypeJson] }
context "different types when overloaded" $ do
@@ -919,7 +926,7 @@ spec actualPgVersion =
it "can set the same http header twice" $
get "/rpc/set_cookie_twice"
`shouldRespondWith`
""
"null"
{ matchHeaders = [ matchContentTypeJson
, "Set-Cookie" <:> "sessionid=38afes7a8; HttpOnly; Path=/"
, "Set-Cookie" <:> "id=a3fWa; Expires=Wed, 21 Oct 2015 07:28:00 GMT; Secure; HttpOnly" ]}
+4
View File
@@ -1051,6 +1051,10 @@ $$ language sql;
create function test.ret_void() returns void as '' language sql;
create or replace function test.ret_null() returns int as $$
select null::int;
$$ language sql;
create function test.ret_base64_bin() returns text as $$
select i.img from test.images_base64 i where i.name = 'A.png';
$$ language sql;