Do we want to change %p to pull from this variable and save the snprintf()? Not a measurable savings, more or a don't-repeat-yourself thing.
I checked the code, and I don't think so. Current state is safer (I think). The psql's variables are not protected, and I think, so is safer, better to
read the value for prompt directly by usage of the libpq API instead read the possibly "customized" variable. I see possible inconsistency,
but again, the same inconsistency can be for variables USER and DBNAME too, and I am not able to say what is significantly better. Just prompt shows
real value, and the related variable is +/- copy in connection time.
I am not 100% sure in this area what is better, but the change requires wider and more general discussion, and I don't think the benefits of possible
change are enough. There are just two possible solutions - we can protect some psql's variables (and it can do some compatibility issues), or we
need to accept, so the value in prompt can be fake. It is better to not touch it :-).