grant Verified current stable Not installed? Security

Grant / Grant Authorities To Role

Grant Authorities To Role

Assigns specific privileges to a role on a designated object.

$
Terminal
grant <action_list> on <object_type> <object_name> to role <role_name>;

When To Use

When setting up access controls for a database operation.

Pro Tip

Consider using RESTRICT if you want to ensure that no other roles inherit these privileges.

Command Builder

Tune the command before you copy it

Back to syntax
$
Generated Command
grant <action_list> on <object_type> <object_name> to role <role_name>;

Anatomy of Output

Understanding the result

GRANT SELECT, INSERT ON TABLE my_table TO ROLE my_role; Command

Executes privileges assignment.

GRANT succeeded. Output

Confirms the action was successful.

ERROR: insufficient privileges to grant SELECT on TABLE my_table. Warning

Indicates permission issues with the object.

Power User Variants

Optimized versions

GRANT ALL PRIVILEGES ON my_table TO ROLE my_role;

Grants all possible actions on the object.

GRANT SELECT ON ALL TABLES IN SCHEMA public TO ROLE my_role;

Grants SELECT on every table in the specified schema.

Troubleshooting

Common pitfalls

ERROR: ROLE "my_role" does not exist

Solution: Verify that the specified role name is correct.

ERROR: cannot grant SELECT on TABLE "my_table" because role lacks permission

Solution: Ensure the origin role has necessary privileges.

ERROR: invalid input syntax for type object_type

Solution: Double-check object type and naming conventions.

Command Breakdown

What each part is doing

grant
Base Command
The executable that performs this operation. Here it runs Grant before the shell applies any redirect operators.
<action_list>
action list
The value supplied for action list.
<object_type>
object type
The value supplied for object type.
<object_name>
object name
The value supplied for object name.
<role_name>
role name
The value supplied for role name.

Alternative Approaches

Comparable commands in other tools

Alternative security tools for the same job.