The docs page states (emphasis mine)
psql returns 0 to the shell if it finished normally, 1 if a fatal error of its own occurs (e.g. out of memory, file not found), 2 if the connection to the server went bad and the session was not interactive, and 3 if an error occurred in a script and the variable ON_ERROR_STOP was set.
However, I seem to be unable to induce exit code 3.
bash-4.2$ uname -a Linux mvpg-centos-76.vagrantup.com 3.10.0-957.21.3.el7.x86_64 #1 SMP Tue Jun 18 16:35:19 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux bash-4.2$ psql --version psql (PostgreSQL) 10.12 bash-4.2$ psql -v ON_ERROR_STOP=1 -c 'select 1/0;' ERROR: division by zero bash-4.2$ echo $? 1 bash-4.2$
I've also reproduced this behaviour on FreeBSD 11.3 and Darwin 19.3. Am I misunderstanding the documentation or using a faulty syntax?