Please is there a manner to create user if not exit.
CREATE USER sup_ WITH PASSWORD 'postgres';
When i executed two times got error saying that sup_ exist. How should i do please to correct my query ?
Thank you?
Please is there a manner to create user if not exit.
CREATE USER sup_ WITH PASSWORD 'postgres';
When i executed two times got error saying that sup_ exist. How should i do please to correct my query ?
Thank you?
There's no IF NOT EXISTS
clause for CREATE ROLE
.
You'll probably want to use PL/pgSQL to solve your problem. Have a look at this question, it's basically the same one and the answers are really thorough.
First check whether the user exists or not to avoid error. User below query:
Do
$do$
BEGIN
IF NOT EXISTS (SELECT * FROM pg_user WHERE usename = 'sup_')then
CREATE USER sup_ WITH PASSWORD 'postgres';
END IF;
end
$do$