GRANT (Grant Privileges)

Last updated: 2026-11-04

GRANT (Grant Privileges)

GRANT gives privileges on an object to a role. PostgreSQL's permission model is role-centric: privileges are granted to roles, and users gain them by becoming members of those roles. A role can also be granted to another role, which lets you build layers of privileges.

Kindcommand
Example LanguageSQL

📝 Syntax

GRANT { <privilege> | ALL [PRIVILEGES] } ON [TABLE] <table> [, ...]
TO <role> [, ...]
[WITH GRANT OPTION]

-- other object types work too
GRANT { SELECT | INSERT | UPDATE | DELETE } ON <table> TO <role>;

⚙️ Parameters

SELECT / INSERT / UPDATE / DELETEThe specific table-level privileges
ON <object>The table, sequence, or schema the privilege applies to
TO <role>The role that receives the privilege
WITH GRANT OPTIONLets the role grant the privilege onward

Returns:No return value. The privilege takes effect immediately.

▶ Example

Runs real PostgreSQL 18 right in your browser (PGlite WASM, nothing to install). Press ▶ Run and the result appears in the panel below.

Output:

DROP TABLE
CREATE TABLE
INSERT 0 2
DO
GRANT
   grantee    | privilege_type
--------------+---------------
report_reader | SELECT

📌 Key Points

More case studies coming soon.

📚 Related Reference

❓ FAQ

QHow do I inspect the privileges on a table?
AQuery information_schema.role_table_grants to see every grantee and privilege on every table; in psql, \dp shows the same information.
QWhat is the difference between a role and a user?
AThere is none. A role created with CREATE ROLE cannot log in by default; add LOGIN to use it as a login user.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

Content reviewed by MOTO · Found an error? Report it

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏