Opened 7 years ago

Closed 6 years ago

#1759 closed enhancement (fixed)

FROM clause in UPDATE statement

Reported by: Dimitar Misev Owned by: bbell
Priority: critical Milestone: 9.7
Component: qlparser Version: development
Keywords: Cc: Peter Baumann, Bang Pham Huu, Vlad Merticariu, bbell
Complexity: Medium

Description (last modified by bbell)

It is not possible to perform UPDATE query on coll A based on the values of coll B, i.e. something like

UPDATE A SET A[..]
ASSIGN B
WHERE oid(B) = ..

What's missing in the syntax is support for specifying multiple collections, e.g.

UPDATE A SET A[..]
ASSIGN B
FROM B

Formally speaking, the solution should take the current "UPDATE" options and extend them using a "FROM" clause. This can be achieved by introducing syntax for the following grammar constructions:

Added UPDATE grammar:

updateExp : update iteratedCollection set updateSpec
assign generalExp
where generalExp
from collectionList

and

update iteratedCollection set updateSpec
assign generalExp
from collectionList

Change History (9)

comment:1 by Dimitar Misev, 7 years ago

Or maybe just assume there's a FROM clause implicitly like we do for A.

comment:2 by Vlad Merticariu, 7 years ago

Currently the implicit FROM clause for A comes from the UPDATE itself:

UPDATE A as a
SET a ..

We could allow

UPDATE A as a,

B as b

SET a = b …

Both approaches are valid (https://stackoverflow.com/questions/224732/sql-update-from-one-table-to-another-based-on-a-id-match). Looking at the code, I think allowing several collections in the UPDATE clause is more straight forward to implement.

comment:3 by Peter Baumann, 7 years ago

my first idea was a nested query, which is already discussed in stackoverflow as I see. If we don't want to use that (and it comes at a complexity price for the user) then I find the implicit FROM ok, in particular as it seems a lower hanging fruit.

comment:4 by Dimitar Misev, 7 years ago

Description: modified (diff)
Owner: set to bbell
Status: newassigned

comment:5 by Peter Baumann, 7 years ago

of course, having a FROM clause would allow a clear indication of what is to be updated. But I'd see this as cream in the coffee given that the "UPDATE A, B" approach has precedent out there.

comment:6 by Dimitar Misev, 7 years ago

Milestone: 9.69.7

comment:7 by bbell, 7 years ago

Priority: majorcritical

comment:8 by bbell, 6 years ago

Description: modified (diff)

comment:9 by Dimitar Misev, 6 years ago

Resolution: fixed
Status: assignedclosed
Note: See TracTickets for help on using tickets.