Postgrest doesn't like you executing arbitrary queries, but you can get around it by defining a function that executes the query for you:
$ psql mydb
mydb=# create function custom_query(query text) returns setof json as $f$
begin
return query execute format('with tmp as (%s) select row_to_json(tmp.*) from tmp;', query);
end
$f$ language plpgsql;
CREATE FUNCTION
You can then execute arbitrary queries by POST'ing to this function:
$ curl -XPOST -H "Content-Type: application/json" http://127.0.0.1:3002/rpc/custom_query \
-d -d '{"query": "select date_trunc($$month$$, \"Date\") as month, avg(\"Quality\") as quality from sleep group by 1"}'
Voila! Custom queries through Postgrest.
How to do the same with prepared queries to prevent SQL injections?