Database view
A saved query you can read like a table. It gives complicated or restricted data a simple, reusable name.
See it
What it is
A database view is a named SELECT statement that you can query as if it were a table. A regular view stores the query definition, not its result, so the database reads the underlying tables whenever you use it. Views can give callers a smaller, steadier interface than the schema underneath.
Reach for one to reuse a complicated join, expose only approved columns, or keep an old query shape working while tables change. In PostgreSQL, permissions can be granted on the view without granting the same direct access to every base table.
Gotcha: a view is not automatically a performance feature. A slow SELECT usually remains slow behind a nicer name, and stacked views can make the real query hard to see. Updates through a view also have strict rules, so treat a view as read-only unless its write behavior is deliberate and tested.
Ask AI for it
Create a PostgreSQL view for this query with CREATE VIEW, an explicit column list, and no SELECT *. Grant callers SELECT on the view rather than the base tables, add security_barrier if caller-supplied filters must not leak protected rows through pushed-down functions, and use WITH LOCAL CHECK OPTION if the view is intentionally writable. Show the SQL migration, the matching rollback, and example SELECT and UPDATE statements that prove the access and write rules.