Fixes 500 when set returning function returns an empty row set [fix #332]
This commit is contained in:
@@ -116,7 +116,7 @@ asJsonWithCount = withCount . asJson
|
||||
asJson :: StatementT
|
||||
asJson s = s {
|
||||
B.stmtTemplate =
|
||||
"array_to_json(array_agg(row_to_json(t)))::character varying from ("
|
||||
"array_to_json(coalesce(array_agg(row_to_json(t)), '{}'))::character varying from ("
|
||||
<> B.stmtTemplate s <> ") t" }
|
||||
|
||||
withCount :: StatementT
|
||||
|
||||
@@ -310,6 +310,11 @@ spec =
|
||||
post "/rpc/getitemrange" [json| { "min": 2, "max": 4 } |] `shouldRespondWith`
|
||||
[json| [ {"id": 3}, {"id":4} ] |]
|
||||
|
||||
context "a proc that returns an empty rowset" $
|
||||
it "returns empty json array" $
|
||||
post "/rpc/test_empty_rowset" [json| {} |] `shouldRespondWith`
|
||||
[json| [] |]
|
||||
|
||||
context "a proc that returns plain text" $
|
||||
it "returns proper json" $
|
||||
post "/rpc/sayhello" [json| { "name": "world" } |] `shouldRespondWith`
|
||||
|
||||
Vendored
+7
-1
@@ -297,7 +297,9 @@ CREATE FUNCTION "1".getitemrange(min bigint, max bigint) RETURNS SETOF "1".items
|
||||
SELECT * FROM "1".items WHERE id > $1 AND id <= $2;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
|
||||
CREATE FUNCTION "1".test_empty_rowset() RETURNS SETOF int AS $$
|
||||
SELECT null::int FROM (SELECT 1) a WHERE false;
|
||||
$$ LANGUAGE SQL;
|
||||
|
||||
CREATE FUNCTION "1".sayhello(name text) RETURNS text AS $$
|
||||
SELECT 'Hello, ' || $1;
|
||||
@@ -663,6 +665,10 @@ REVOKE ALL ON FUNCTION getitemrange(bigint, bigint) FROM postgrest_test;
|
||||
GRANT EXECUTE ON FUNCTION getitemrange(bigint, bigint) TO postgrest_test;
|
||||
GRANT EXECUTE ON FUNCTION getitemrange(bigint, bigint) TO postgrest_anonymous;
|
||||
|
||||
REVOKE ALL ON FUNCTION test_empty_rowset() FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION test_empty_rowset() FROM postgrest_test;
|
||||
GRANT EXECUTE ON FUNCTION test_empty_rowset() TO postgrest_test;
|
||||
GRANT EXECUTE ON FUNCTION test_empty_rowset() TO postgrest_anonymous;
|
||||
|
||||
REVOKE ALL ON FUNCTION sayhello(text) FROM PUBLIC;
|
||||
REVOKE ALL ON FUNCTION sayhello(text) FROM postgrest_test;
|
||||
|
||||
Reference in New Issue
Block a user