From 441f55244b19b7ffdadf77dc0c9bcd311ec56d00 Mon Sep 17 00:00:00 2001 From: Dean Rasheed Date: Thu, 27 Mar 2025 14:19:15 +0000 Subject: [PATCH v1 2/2] doc: Improve the "Policies Applied by Command Type" table. This table was missing MERGE ... THEN DELETE and some of the policies applied during INSERT ... ON CONFLICT and MERGE. Fix that, and try to improve readability by listing the various MERGE cases separately, rather than together with INSERT/UPDATE/DELETE. In addition, correct the paragraph above the table to note that an INSERT ... ON CONFLICT DO NOTHING/UPDATE checks all new rows against the INSERT policy expressions, regardless of whether the rows end up being inserted. --- doc/src/sgml/ref/create_policy.sgml | 70 +++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 13 deletions(-) diff --git a/doc/src/sgml/ref/create_policy.sgml b/doc/src/sgml/ref/create_policy.sgml index e76c342d3da..2196fbb1174 100644 --- a/doc/src/sgml/ref/create_policy.sgml +++ b/doc/src/sgml/ref/create_policy.sgml @@ -293,9 +293,9 @@ CREATE POLICY name ON Note that INSERT with ON CONFLICT DO - UPDATE checks INSERT policies' - WITH CHECK expressions only for rows appended - to the relation by the INSERT path. + NOTHING/UPDATE checks INSERT policies' + WITH CHECK expressions for all rows, regardless + of whether they end up being inserted. @@ -440,15 +440,7 @@ CREATE POLICY name ON - INSERT / MERGE ... THEN INSERT - - New row - - - - - - INSERT ... RETURNING + INSERT New row @@ -464,7 +456,7 @@ CREATE POLICY name ON - UPDATE / MERGE ... THEN UPDATE + UPDATE Existing & new rows @@ -483,14 +475,66 @@ CREATE POLICY name ON Existing row + + INSERT ... ON CONFLICT + New row + New row + + + + ON CONFLICT DO UPDATE + + Existing & new rows + + New row of the auxiliary UPDATE command, which + might be different from the new row of the original + INSERT command. + + + + + Existing row + + New row + + + + + MERGE + All candidate source & target rows + + + + + + + MERGE ... THEN INSERT + + New row + + New row + + + + + + MERGE ... THEN UPDATE Existing & new rows Existing row New row + + MERGE ... THEN DELETE + Existing row + + + + Existing row + -- 2.43.0