Iuri, many PostgreSQL installations, many extensions are already included, can can do simply in psql:
CREATE EXTENSION IF NOT EXISTS tablefunc;
If this works, your are done, you can use the crosstab family
oacs-5-10=# \df crosstab
crosstab crosstab2 crosstab3 crosstab4
otherwise progress as Dave suggested
see also:
https://stackoverflow.com/questions/3002499/postgresql-crosstab-query
https://www.vertabelo.com/blog/creating-pivot-tables-in-postgresql-using-the-crosstab-function/