View permissions and least privilege
Overview
A view can expose selected columns or rows while hiding implementation details. It is not by itself a security boundary: access depends on privileges, execution context and database configuration. PostgreSQL can grant SELECT on a view to a role that lacks direct access to its base table. SQLite has no native per-role GRANT/REVOKE system; the two examples intentionally demonstrate projection without role enforcement.
First example
SELECT id,name,price FROM vw_public ORDER BY id;Observed SQLite result (rows in JSON):
[ [ 1, "Pen", 100 ], [ 2, "Paper", 200 ], [ 3, "Tape", 300 ]]How it works
The public catalog omits cost; direct access to the base table still exposes it in the unrestricted SQLite connection. The PostgreSQL lab uses a separate NOLOGIN role and a grant only on the view. With default view security, underlying relation access is normally checked as the view owner; security_invoker=true instead checks the caller. Security-barrier views can help protect row filtering from unsafe predicate reordering but are not a replacement for grants or row-level security. Check schema USAGE, role membership, inherited grants, function permissions and row-level security policy context. Test actual low-privilege sessions. SQLite applications must control database file and connection access; an authorizer can enforce a narrowly designed policy at statement preparation, not server-side roles.
Practical example
SELECT id,cost FROM vw_product ORDER BY id;Observed SQLite result (rows in JSON):
[ [ 1, 60 ], [ 2, 120 ], [ 3, 180 ]]Practice and mistakes
Practice: query vw_public and identify its exposed columns, then query cost directly on the disposable base table. Hint 1: explicit projection determines view columns. Hint 2: the unrestricted connection still has base access. Expect cost to be missing from the view but readable from the table. Mistake: hiding a column in a view and granting everyone base-table access.