In today’s article, we will learn how to define and get privileges such as Select, Insert, Update and Delete to specific tables in a Postgresql database.
Define Privileges
If you are dealing with database management, there may be times when you want to access only one view or only one table in a database.
In such cases, permissions are defined only for the relevant object with the help of the GRANT command.
Syntax:
1 |
GRANT SELECT, INSERT, UPDATE, DELETE TO user_name; |
For example, let’s define select permission to the Faruk user in our students table.
1 |
GRANT select ON ogrenciler TO faruk; |
For example, let’s define insert permission to the Faruk user in our students table.
1 |
GRANT insert ON ogrenciler TO faruk; |
For example, let’s define update permission to the Faruk user in our students table.
1 |
GRANT update ON ogrenciler TO faruk; |
For example, let’s define delete permission to the Faruk user in our students table.
1 |
GRANT delete ON ogrenciler TO faruk; |
Get Privileges
1 |
GRANT SELECT,INSERT,UPDATE,DELETE TO user_name; |
For example, let’s get select permission to the Faruk user in our students table.
1 |
REVOKE select ON ogrenciler FROM faruk; |
For example, let’s get insert permission to the Faruk user in our students table.
1 |
REVOKE insert ON ogrenciler FROM faruk; |
For example, let’s get update permission to the Faruk user in our students table.
1 |
REVOKE update ON ogrenciler FROM faruk; |
For example, let’s get delete permission to the Faruk user in our students table.
1 |
REVOKE delete ON ogrenciler FROM faruk; |
You can use the revoke sentence below to get all the permissions.
1 |
REVOKE select,insert,update,delete ON ogrenciler FROM faruk; |