0

After looking at the docs, I know that you can grant Connect & Create Privileges by using the following commands:

GRANT CREATE ON DATABASE <db_name> TO user;
GRANT CONNECT ON DATABASE <db_name> TO user;

How do I grant these privileges on the current database without specifying it's name?

I'm trying to write a script which will be used to grant all rights whenever a new database is created by my application, and hence I don't know what the name will be while writing the script.

2

You could use a DO block with dynamic SQL:

do 
$$ 
begin
  execute format('grant create, connect on database %I to %I', current_database(), 'some_user');
end;
$$;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.