I'd like to set up a postgres view which outputs its results as json.
The view should query a table called events:
CREATE OR REPLACE VIEW jsonview AS
SELECT array_to_json(array_agg(t)) as events_as_json
FROM (SELECT * FROM events)t
and give results in a json. This works but I now, I'd like to specify the output of the view with something like this:
SELECT * FROM jsonview
WHERE events.year_begin = 1552;
But this produces an error due to non existing entry. Any suggestions?