Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support dot notation on UPDATE ... SET #84

Closed
asdine opened this issue May 19, 2020 · 3 comments · Fixed by #127 or #174
Closed

Support dot notation on UPDATE ... SET #84

asdine opened this issue May 19, 2020 · 3 comments · Fixed by #127 or #174
Labels
sql SQL API and syntax
Milestone

Comments

@asdine
Copy link
Collaborator

asdine commented May 19, 2020

Currently, the UPDATE clause only accepts simple top-level fields foo.
We should be able to update nested fields or array indexes using dot notation.

UPDATE users SET a.3.name = [1, 2, 3];

Because nested values can be tricky, the SET clause must only set a value when it is possible. If we take the example above, the document must respect the following requirements in order to be settable:

  • a is an array
  • a.3 exists and is a document
  • a.3.name may or may not exist (same rules as for top-level fields, see below)

Currently, the rule is: if the field doesn't exist, we create it, otherwise we replace it with the new value.
With this change, the rule still applies but only for the element of the dot notation path that is the most to the right.

Exception for arrays

INSERT INTO users (a) VALUES ([1, 0, 0]), ([2, 0]);
UPDATE users SET a.2 = 1;
SELECT * FROM users WHERE a.2 = 1;
{"a": [1, 0, 1]}

This example shows that the above rule must not apply for arrays. If the array index doesn't exist, it must not be created.

@asdine
Copy link
Collaborator Author

asdine commented Aug 25, 2020

I'm reopening this issue as there are still some bugs in the proposed PR. The PR has been reverted and the issue is scheduled for v0.8

@asdine asdine reopened this Aug 25, 2020
@asdine asdine added this to the v0.8.0 milestone Aug 25, 2020
@tzzed
Copy link
Contributor

tzzed commented Aug 27, 2020

When the field using backquotes with spaces like this some "field ", the spaces must be deleted or not?
inputs:
` some "field" ` OR `a.` b ` . c`
outputs :

`some "field" ` OR `a.b.c`

Spaces should be deleted.
Is the expected behaviour?

@tzzed
Copy link
Contributor

tzzed commented Aug 27, 2020

Found the answer in TestParserPath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sql SQL API and syntax
Projects
None yet
2 participants