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
USINGpolicy failure causes the statement to fail. Normally,USINGfilters out rows silently. - (b): Like ✓(a), but only applied when the statement references row columns (
WHERE,SET, orRETURNING). If theUSINGpolicy is violated, the statement fails.
ON CONFLICT... DO NOTHING: CockroachDB does not run the constraint and row-level policy checks on theVALUESclause 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 anorders table.
Known limitations
ON CONFLICT... DO NOTHING: CockroachDB does not run the constraint and row-level policy checks on theVALUESclause if the candidate row has a conflict..

