This request throws an exception:
SELECT cal_id.nextval , EXTRACT(YEAR FROM start_date) , count(placement_id) FROM placement group by year;
This is because you cannot select a sequence value in a query with a group by clause.
In addition, the group by clause should include all non-aggregated expressions from the select clause, which you donβt have. I assume that year is an alias of EXTRACT(YEAR FROM start_date) , in which case this is the query you need:
INSERT INTO placement_cal SELECT cal_id.nextval, year, cnt FROM ( SELECT EXTRACT(YEAR FROM start_date) year, count(placement_id) cnt FROM placement group by EXTRACT(YEAR FROM start_date) );
source share