Skip to contents

Construct a row level security policy

Usage

rls_construct_policy(
  name,
  table,
  as = NULL,
  command = NULL,
  role = NULL,
  using = NULL,
  check = NULL
)

Arguments

name

(character) name of the policy to be created. This must be distinct from the name of any other policy for the table. required

table

(character) the table to apply the policy to. required

as

(character) permissive (default) or restrictive. permissive combines with "OR" while restrictive combines with "AND"

command

(character) the command to which the policy applies. Valid options are ALL (default), SELECT, INSERT, UPDATE, and DELETE

role

(character) The role(s) to which the policy is to be applied. The default is PUBLIC, which will apply the policy to all roles.

using

(character) Specifies a filter that is applied to the WHERE clause of a query. Rows for which the expression returns true will be visible. Any rows for which the expression returns false or null will not be visible to the user (in a SELECT), and will not be available for modification (in an UPDATE or DELETE). Such rows are silently suppressed; no error is reported.

check

(character) the check condition; any SQL conditional expression that returns a boolean. This expression will be used in INSERT and UPDATE queries against the table if row-level security is enabled. Only rows for which the expression evaluates to true will be allowed. Is evaluated against the proposed new contents of the row, not the original contents

Value

s3 object of class rls_policy

Details

We've chosen more intuitive names for policy parameters, so here's a mapping of function parameters to the PostgreSQL parameters:

  • (this function: PostgreSQL)

  • table: on

  • command: for

  • role: to

  • check: with

Examples

x <- rls_construct_policy(
  name = "hide_confidential",
  table = "sometable",
  check = "confidential BOOLEAN",
  using = "confidential = false"
)
x
#> <rls_policy>
#>   policy name: hide_confidential
#>   table: sometable
#>   using: confidential = false
#>   check: confidential BOOLEAN