Skip to main content
The CREATE POLICY statement defines a new policy on a table.

Syntax

Parameters

The USING and WITH CHECK expressions can reference table columns and use session-specific (e.g., current_user(), session_user()) and . However, these expressions cannot contain a subexpression.

Policies by statement type

The following table shows which policies are applied to which statement types, with additional considerations listed after the table.
  • ✓: Always applied.
  • (a): A USING policy failure causes the statement to fail. Normally, USING filters out rows silently.
  • (b): Like ✓(a), but only applied when the statement references row columns ( WHERE, SET, or RETURNING ). If the USING policy is violated, the statement fails.
Additional considerations include:
  • ON CONFLICT... DO NOTHING: CockroachDB does not run the constraint and row-level policy checks on the VALUES clause if the candidate row has a conflict.. This is a known limitation.

Examples

In this example, you will allow users to see or modify only their own rows in an orders table.

Known limitations

  • ON CONFLICT... DO NOTHING: CockroachDB does not run the constraint and row-level policy checks on the VALUES clause if the candidate row has a conflict..

See also