How to check if a postgres user exists?

前端 未结 4 1674
一生所求
一生所求 2021-01-30 02:04

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

4条回答
  •  隐瞒了意图╮
    2021-01-30 02:40

    psql -qtA -c "\du USR_NAME" | cut -d "|" -f 1

    [[ -n $(psql -qtA -c "\du ${1}" | cut -d "|" -f 1) ]] && echo "exists" || echo "does not exist"

提交回复
热议问题