Search code examples
postgresqlviewpostgresql-9.5row-level-security

Is possible to create row level security policy for a postgresql view?


We need to implement row-level security policy for a PostgreSQL View. Is there any option to do this?

Thank You


Solution

  • CREATE VIEW
      view_own_log
    AS SELECT
      these,
      fields,
      only
    FROM
      restricted_log_table
    WHERE
      username=user;
    

    user is the logged on user.

    You can create more sophisticated WHERE clauses if needed. Have the table access limited to minimum and use GRANT to give access to the view.