Drops a user from a database. Multiple users can be dropped with a single DROP USER command. You must be a database superuser to execute this command.
DROP USER [ IF EXISTS ] name [, ... ]
- IF EXISTS
Clause that indicates that if the specified user account doesn’t exist, the command should make no changes and return a message that the user account doesn't exist, rather than terminating with an error.
This clause is useful when scripting, so the script doesn’t fail if DROP USER runs against a nonexistent user account.
Name of the user account to remove. You can specify multiple user accounts, with a comma separating each account name from the next.
You cannot drop a user if the user owns any database object, such as a schema, database, table, or view, or if the user has any privileges on a table, database, or group. If you attempt to drop such a user, you will receive one of the following errors.
ERROR: user "username" cannot be dropped because the user owns some object [SQL State=55006] ERROR: user "username" cannot be dropped because the user has a privilege on some object [SQL State=55006]
Amazon Redshift checks only the current database before dropping a user. DROP USER doesn't return an error if the user owns database objects or has any privileges on objects in another database. If you drop a user that owns objects in another database, the owner for those objects is changed to 'unknown'.
drop database dwdatabase; alter schema dw owner to dwadmin; revoke all on table dwtable from dwuser; drop user dwuser;
The following example drops a user account called danny:
drop user danny;
The following example drops two user accounts, danny and billybob:
drop user danny, billybob;
The following example drops the user account danny if it exists, or does nothing and returns a message if it does not:
drop user if exists danny;