SQLite Forum

Feature request: extensions to UPDATE
Login
Yes.

In theory an update with a FROM clause is a CURSORed update.  That is:

```
UPDATE a
   SET ...
 FROM b[, ...]
WHERE ...
```

is equivalent to defining a cursor thusly:

```
SELECT *
  FROM a,b[, ...]
 WHERE ...
FOR UPDATE OF a
```
and then for each candidate executing
```
UPDATE a SET ... WHERE CURRENT OF CURSOR
```

Different RDBMS permit different definitions of the update and the cursor.  In some implementations, one can update *ANY* table by simply using qualifications in the SET clause.  Sometimes the target "a" is included in the cursor, and sometimes it merely specifies WHICH table in the cursor is the default for unqualified names in the SET clause.  That is, sometimes:

```
UPDATE a
   SET bunny = 1
  FROM b
 WHERE a.this == b.that
```
is an invalid statement because "a" is not part of the cursor, and 
```
UPDATE a
   SET bunny = 1
  FROM a, b
 WHERE a.this == b.that
```
is valid because the cursor is actually defined by the tables in the FROM clauses and you cannot update a table that does not appear there.

However, you can (currently) achieve the same effect by using the INSERT or REPLACE and getting rid of REPLACE and making it an INSERT ... ON CONFLICT UPDATE statement, processing every row as a CONFLICT. As in:

`INSERT INTO a (rowid, bunny) SELECT a.rowid, 1 as bunny FROM a, b WHERE a.this==b.that ON CONFLICT (rowid) UPDATE SET bunny = excluded.bunny;`