Column privileges choose columns. To choose rows too, give access through a view (Chapter 12).
sql
CREATE VIEW public_products AS
SELECT name, price FROM products WHERE stock > 0;
GRANT SELECT ON public_products TO partner;partnerSELECT on the view
public_productsowner's privileges
productsno grant to partner
- A view reads its tables with the privileges of the view's owner, the role that created it.
partnerneeds no privilege onproducts. - The view's SELECT list chooses the columns. Its WHERE chooses the rows.
partnercannot readproductsdirectly. Every query goes through the view.
products
| id | name | price | stock |
|---|---|---|---|
| 1 | Kraken Plush | 29.99 | 40 |
| 2 | Pod Golem Plush | 34.50 | 12 |
| 3 | Daemon Cat Plush | 24.00 | 0 |
| Need | Use |
|---|---|
| Hide some columns | column privileges or a view |
| Hide some rows | a view |
| Show a computed or joined result | a view |