Opened 7 years ago

Last modified 6 years ago

#1759 closed enhancement

FROM clause in UPDATE statement — at Version 4

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 Dimitar Misev)

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, B SET A[..]
ASSIGN B
WHERE oid(B) = ..

Change History (4)

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
Note: See TracTickets for help on using tickets.