Skip to content

Commit

Permalink
Fix <do update> and <do replace> grammar and add an extra example (#73)
Browse files Browse the repository at this point in the history
This PR fixes <do update> and <do replace> grammar as it does not specify the [ WHERE ] for all the branches.
In addition, it adds an example for conditionally DO REPLACE.
  • Loading branch information
am357 authored Jan 4, 2024
1 parent 101390a commit 74dd8d4
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions RFCs/0011-partiql-insert.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,15 @@ Note:
<index target> ::= <index attr name>
<conflict action> ::= DO NOTHING
| DO UPDATE <do update>
| DO REPLACE <do replace>
| DO UPDATE <do update> [ WHERE <condition> ]
| DO REPLACE <do replace> [ WHERE <condition> ]
<do update> ::= EXCLUDED
| SET <attr values> [, <attr values>]...
[ WHERE <condition> ]
<do replace> ::= EXCLUDED
| SET <attr values> [, <attr values>]...
| VALUE <tuple value>
[ WHERE <condition> ]
<attr values> ::= {
<attr name> = { <value expr> | DEFAULT }
Expand Down Expand Up @@ -898,6 +896,22 @@ ON CONFLICT
DO REPLACE EXCLUDED;
```

##### Example 4.2.14

The following example conditionally replaces the existing item with the item provided by `INSERT` statement. Note that as an outcome the statement does not replace the existing item because the condition is not met.

```SQL
-- Existing items is:
-- {'HK': 1, 'RK': 1, 'myAttr': 5 },
-- Outcome is:
-- {'HK': 1, 'RK': 1, 'myAttr': 5 },

INSERT into Customers
<<{ 'HK': 2, 'RK': 1, 'myAttr': 13, 'anotherAttr': 15 }>>
ON CONFLICT
DO REPLACE EXCLUDED WHERE EXCLUDED.anotherAttr = 12;
```

## 5. Other Examples
Insert or update new distributors as appropriate. Assumes a unique index has been defined that constrains values appearing in the `did` attribute. Note that the special `excluded` table is used to reference values originally proposed for insertion:

Expand Down

0 comments on commit 74dd8d4

Please sign in to comment.