GRANT (Schema)

Grants schema privileges to users and roles.

Note: By default, new users cannot access schema PUBLIC. You must explicitly grant all new users USAGE privileges on the PUBLIC schema.

Syntax

GRANT { privilege[,…] | ALL [ PRIVILEGES ] }
   ON SCHEMA [database.]schema[,…]
   TO grantee[,…] 
   [ WITH GRANT OPTION ]  

Parameters

privilege

One of the following privileges:

  • USAGE: Enables access to objects in the specified schemas. Grantees can then be granted privileges on individual objects in these schemas in order to access them, through GRANT TABLE and GRANT VIEW.
  • CREATE: Create tables and views.

The following privileges are automatically granted on new tables and views if inherited privileges are already enabled for the database and this schema:

  • SELECTQuery tables and views of this schema.
  • INSERTInsert rows into tables of this schema, or and load data into tables with COPY.
  • UPDATE: Update rows of tables of this schema.
  • DELETE: Delete rows of tables of this schema.
  • REFERENCES: Create foreign key constraints for tables of this schema. This privilege must also be set on both referencing and referenced tables.
  • TRUNCATE: Truncate table contents.
ALL [PRIVILEGES]

Grants CREATE and USAGE privileges.

The optional keyword PRIVILEGES conforms with the SQL standard.

[database.]schema

Specifies a target schema. If you specify a database, it must be the current database.

grantee

Specifies who is granted privileges, one of the following:

WITH GRANT OPTION

Gives grantee the privilege to grant the same privileges to other users or roles. For details, see How to Grant Privileges in the Administrator's Guide.

Privileges

One of the following:

  • Superuser
  • Privileges grantee who was given the option (WITH GRANT OPTION) of extending these privileges to other users

Examples

This example shows how to grant user Joe usage on schema online_sales.

=> CREATE USER Joe;
CREATE USER
=> GRANT USAGE ON SCHEMA online_sales TO Joe;
GRANT PRIVILEGE

See Also