Query to get the number of errors reported by PostgreSQL
This is not tracked inside the database.

You could mine the log file for ERROR entries &mdash; log_destination = 'csvlog' will make it easier.

One option to process csvlogs (thanks, a_horse_with_no_name!) is to use them with a file_fdw foreign table to access them with SQL from PostgreSQL.