You almost had it, but better start here plpgsql
Some will point that PL/pgSQL
is not the only way to write Stored Procedures for PostgreSQL and they will be right (that’s one of the advantages of Postgres), but on the other hand PL/pgSQL
is nice and relatively easy to start with.