createuser allows creation of a user (ROLE) in PostgreSQL. Is there a simple way to check if that user(name) exists already? Otherwise createuser returns with an er
createuser
Following the same idea than to check if a db exists
psql -t -c '\du' | cut -d \| -f 1 | grep -qw
and you can use it in a script like this:
if psql -t -c '\du' | cut -d \| -f 1 | grep -qw ; then # user exists # $? is 0 else # ruh-roh # $? is 1 fi