Learning center

Check PostgreSQL column grants when SELECT star is denied

When a query with named columns works and SELECT fails, compare the role's column access with the expanded projection. A role with column-level SELECT may read the permitted columns without having table-level SELECT.

In a fictional support tool, case_viewer may read case_id and status on reporting.cases. The tool starts generating a wildcard projection after a schema change adds internal_notes. A privilege inquiry can check that column without fetching case data.

SELECT has_column_privilege('case_viewer', 'reporting.cases',
                            'internal_notes', 'SELECT');

False supports the projection mismatch if the original denial used that effective role and table. List the approved fields explicitly if the tool still needs only those fields. If it now filters or sorts on another column, inspect that reference too. PostgreSQL requires SELECT on columns read by the query, including columns used outside the result list. PostgreSQL GRANT ยท PostgreSQL SELECT permissions

Trace another denied request.

One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. Eligibility and fair-use terms.

Start free with GitHub

Related reading