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

Add ALTER TABLE ... ADD FIELD ... #96

Closed
yaziine opened this issue Jun 12, 2020 · 0 comments · Fixed by #242
Closed

Add ALTER TABLE ... ADD FIELD ... #96

yaziine opened this issue Jun 12, 2020 · 0 comments · Fixed by #242
Labels
enhancement New feature or request sql SQL API and syntax
Milestone

Comments

@yaziine
Copy link
Collaborator

yaziine commented Jun 12, 2020

This is a sub-issue of #94 that focuses on adding a new field constraint.

We should be able to do the following:

genji> CREATE TABLE foo;
genji> INSERT INTO foo VALUES {name: "John Doe"};
genji> ALTER TABLE foo ADD FIELD age int;

If the field age already exists, we should return an error.

NOT NULL

The only constraint supported for now would be NOT NULL but a default value must be specified for the existing documents.

genji> ALTER TABLE foo ADD FIELD age int NOT NULL DEFAULT 50;
genji> SELECT * FROM foo;
{
  "name": "John Doe",
  "age": 50
}

Dot notation

We should also support the dot notation structure.
For example:

genji> ALTER TABLE foo ADD FIELD adress.zip int;
genji> INSERT INTO foo VALUES {name: "John Wick", age: 50, adress: {zip:75000}};
genji> SELECT * FROM foo;
{
  "name": "John Wick",
  "age": 50,
  "adress": {
    "zip": 75000
  }
}
genji> INSERT INTO foo VALUES {name: "John Wick", age: 50, adress: {zip:"Paris"}};
cannot convert "text" to "int64": type "text" incompatible with "integer"

The same goes for arrays:

genji> ALTER TABLE foo ADD FIELD animals.0 text;
genji> INSERT INTO foo VALUES {name: "John Lennon", age: 50, animals: ["bird"]};
genji> SELECT * FROM foo;
{
  "name": "John Lennon",
  "age": 50,
  "animals": [
    "cat",
  ]
}
genji> INSERT INTO foo VALUES {name: "John Lennon", age: 50, animals: [127]};
cannot convert "int8" to "string"
@yaziine yaziine added enhancement New feature or request sql SQL API and syntax labels Jun 12, 2020
@yaziine yaziine added this to the v0.6.0 milestone Jun 12, 2020
@yaziine yaziine self-assigned this Jun 12, 2020
@asdine asdine modified the milestones: v0.6.0, v0.7.0 Jun 28, 2020
@asdine asdine modified the milestones: v0.7.0, v0.8.0 Aug 21, 2020
@asdine asdine modified the milestones: v0.8.0, v0.9.0 Sep 26, 2020
@yaziine yaziine removed their assignment Oct 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request sql SQL API and syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants