IntermediateAdvanced PostgreSQL

Views: virtual tables for access control

The query

SQL
CREATE OR REPLACE VIEW v_employee_public AS
SELECT
  emp_id,
  first_name,
  last_name,
  job_title,
  dept_id,
  hire_date,
  status
  -- salary EXCLUDED for privacy
FROM employees
WHERE status = 'active';

-- Grant access without exposing raw table
GRANT SELECT ON v_employee_public TO readonly_user;
Tested against PostgreSQL 16

Note

Views provide security (hide sensitive columns/rows), abstraction, and simplify complex queries.

Tables referenced