Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit df2361c

Browse files
committed
Doc: add a summary table to the CREATE POLICY docs.
This table summarizes which RLS policy expressions apply to each command type, and whether they apply to the old or new tuples (or both), which saves reading through a lot of text. Rod Taylor, hacked on by me. Reviewed by Fabien Coelho. Discussion: https://postgr.es/m/CAHz80e4HxJShm6m9ZWFrHW=pgd2KP=RZmfFnEccujtPMiAOW5Q@mail.gmail.com
1 parent fa39617 commit df2361c

File tree

1 file changed

+103
-1
lines changed

1 file changed

+103
-1
lines changed

doc/src/sgml/ref/create_policy.sgml

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ CREATE POLICY <replaceable class="parameter">name</replaceable> ON <replaceable
7272
<para>
7373
Policies can be applied for specific commands or for specific roles. The
7474
default for newly created policies is that they apply for all commands and
75-
roles, unless otherwise specified.
75+
roles, unless otherwise specified. Multiple policies may apply to a single
76+
command; see below for more details.
77+
<xref linkend="sql-createpolicy-summary"> summarizes how the different types
78+
of policy apply to specific commands.
7679
</para>
7780

7881
<para>
@@ -353,6 +356,105 @@ CREATE POLICY <replaceable class="parameter">name</replaceable> ON <replaceable
353356
</varlistentry>
354357

355358
</variablelist>
359+
360+
<table id="sql-createpolicy-summary">
361+
<title>Policies Applied by Command Type</title>
362+
<tgroup cols="6">
363+
<colspec colnum="4" colname="update-using">
364+
<colspec colnum="5" colname="update-check">
365+
<spanspec namest="update-using" nameend="update-check" spanname="update">
366+
<thead>
367+
<row>
368+
<entry morerows="1">Command</entry>
369+
<entry><literal>SELECT/ALL policy</literal></entry>
370+
<entry><literal>INSERT/ALL policy</literal></entry>
371+
<entry spanname="update"><literal>UPDATE/ALL policy</literal></entry>
372+
<entry><literal>DELETE/ALL policy</literal></entry>
373+
</row>
374+
<row>
375+
<entry><literal>USING expression</literal></entry>
376+
<entry><literal>WITH CHECK expression</literal></entry>
377+
<entry><literal>USING expression</literal></entry>
378+
<entry><literal>WITH CHECK expression</literal></entry>
379+
<entry><literal>USING expression</literal></entry>
380+
</row>
381+
</thead>
382+
<tbody>
383+
<row>
384+
<entry><command>SELECT</command></entry>
385+
<entry>Existing row</entry>
386+
<entry>&mdash;</entry>
387+
<entry>&mdash;</entry>
388+
<entry>&mdash;</entry>
389+
<entry>&mdash;</entry>
390+
</row>
391+
<row>
392+
<entry><command>SELECT FOR UPDATE/SHARE</command></entry>
393+
<entry>Existing row</entry>
394+
<entry>&mdash;</entry>
395+
<entry>Existing row</entry>
396+
<entry>&mdash;</entry>
397+
<entry>&mdash;</entry>
398+
</row>
399+
<row>
400+
<entry><command>INSERT</command></entry>
401+
<entry>&mdash;</entry>
402+
<entry>New row</entry>
403+
<entry>&mdash;</entry>
404+
<entry>&mdash;</entry>
405+
<entry>&mdash;</entry>
406+
</row>
407+
<row>
408+
<entry><command>INSERT ... RETURNING</command></entry>
409+
<entry>
410+
New row
411+
<footnote id="rls-select-priv">
412+
<para>
413+
If read access is required to the existing or new row (for example,
414+
a <literal>WHERE</literal> or <literal>RETURNING</literal> clause
415+
that refers to columns from the relation).
416+
</para>
417+
</footnote>
418+
</entry>
419+
<entry>New row</entry>
420+
<entry>&mdash;</entry>
421+
<entry>&mdash;</entry>
422+
<entry>&mdash;</entry>
423+
</row>
424+
<row>
425+
<entry><command>UPDATE</command></entry>
426+
<entry>
427+
Existing &amp; new rows
428+
<footnoteref linkend="rls-select-priv">
429+
</entry>
430+
<entry>&mdash;</entry>
431+
<entry>Existing row</entry>
432+
<entry>New row</entry>
433+
<entry>&mdash;</entry>
434+
</row>
435+
<row>
436+
<entry><command>DELETE</command></entry>
437+
<entry>
438+
Existing row
439+
<footnoteref linkend="rls-select-priv">
440+
</entry>
441+
<entry>&mdash;</entry>
442+
<entry>&mdash;</entry>
443+
<entry>&mdash;</entry>
444+
<entry>Existing row</entry>
445+
</row>
446+
<row>
447+
<entry><command>ON CONFLICT DO UPDATE</command></entry>
448+
<entry>Existing &amp; new rows</entry>
449+
<entry>&mdash;</entry>
450+
<entry>Existing row</entry>
451+
<entry>New row</entry>
452+
<entry>&mdash;</entry>
453+
</row>
454+
</tbody>
455+
</tgroup>
456+
</table>
457+
356458
</refsect2>
357459

358460
<refsect2>

0 commit comments

Comments
 (0)