I think the trick here is that the database name that he's trying to check, `postgresql_test_db`, is not part of the actual SQL statement.  Thus, the command-line command will fail and return non-zero exit code if the database doesn't exist, which is what he actually cares about.