diff --git a/src/PostgREST/App.hs b/src/PostgREST/App.hs index d8f625c30..b90cce8c2 100644 --- a/src/PostgREST/App.hs +++ b/src/PostgREST/App.hs @@ -168,10 +168,11 @@ app conf reqBody req = exists <- doesProcExist schema proc if exists then do - row :: Maybe (Identity Text) <- H.maybeEx $ callProc qi $ - fromMaybe M.empty (decode reqBody) - return $ responseLBS status200 [textH] - (cs $ fromMaybe "" $ runIdentity <$> row) + let call = B.Stmt "select " V.empty True <> + asJson (callProc qi $ fromMaybe M.empty (decode reqBody)) + body :: Maybe (Identity Text) <- H.maybeEx call + return $ responseLBS status200 [jsonH] + (cs $ fromMaybe "[]" $ runIdentity <$> body) else return $ responseLBS status404 [] "" -- check that proc exists diff --git a/test/fixtures/schema.sql b/test/fixtures/schema.sql index 805d53273..3d705f9ef 100755 --- a/test/fixtures/schema.sql +++ b/test/fixtures/schema.sql @@ -217,6 +217,17 @@ ALTER SEQUENCE items_id_seq OWNED BY items.id; +CREATE FUNCTION "1".getitemrange(min bigint, max bigint) RETURNS SETOF "1".items AS $$ + SELECT * FROM "1".items WHERE id > $1 AND id <= $2; +$$ LANGUAGE SQL; + + + +CREATE FUNCTION "1".sayhello(name text) RETURNS text AS $$ + SELECT 'Hello, ' || $1; +$$ LANGUAGE SQL; + + CREATE TABLE menagerie ( "integer" integer NOT NULL, double double precision NOT NULL, @@ -521,6 +532,17 @@ GRANT ALL ON TABLE items TO postgrest_test; GRANT ALL ON TABLE items TO postgrest_anonymous; +REVOKE ALL ON FUNCTION getitemrange(bigint, bigint) FROM PUBLIC; +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 sayhello(text) FROM PUBLIC; +REVOKE ALL ON FUNCTION sayhello(text) FROM postgrest_test; +GRANT EXECUTE ON FUNCTION sayhello(text) TO postgrest_test; +GRANT EXECUTE ON FUNCTION sayhello(text) TO postgrest_anonymous; + REVOKE ALL ON SEQUENCE items_id_seq FROM PUBLIC; REVOKE ALL ON SEQUENCE items_id_seq FROM postgrest_test;