Skip to content

Commit

Permalink
Check CREATE TABLE with only generated column(s)
Browse files Browse the repository at this point in the history
  • Loading branch information
gwenn committed Feb 25, 2024
1 parent caa629b commit bcfea15
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
2 changes: 1 addition & 1 deletion checks.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Parse error: temporary table name must be unqualified
sqlite> CREATE TEMPORARY TABLE temp.x AS SELECT 1;
-- OK
```
- [ ] must have at least one non-generated column
- [X] must have at least one non-generated column
```sql
sqlite> CREATE TABLE test(data AS (1));
Parse error: must have at least one non-generated column
Expand Down
8 changes: 8 additions & 0 deletions src/lexer/sql/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,14 @@ fn create_temporary_table_with_qualified_name() {
parse_cmd(b"CREATE TEMPORARY TABLE temp.x AS SELECT 1");
}

#[test]
fn create_table_with_only_generated_column() {
expect_parser_err(
b"CREATE TABLE test(data AS (1))",
"must have at least one non-generated column",
);
}

#[test]
fn create_strict_table_missing_datatype() {
expect_parser_err(b"CREATE TABLE t (c1) STRICT", "missing datatype for t.c1");
Expand Down
13 changes: 11 additions & 2 deletions src/parser/ast/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,17 @@ impl CreateTableBody {
options,
} = self
{
// TODO columns.constraints : check no duplicate names
// TODO constraints: check no duplicated names, use only valid column names
let mut generated_count = 0;
for c in columns {
for cs in c.constraints.iter() {
if let ColumnConstraint::Generated { .. } = cs.constraint {
generated_count += 1;
}
}
}
if generated_count == columns.len() {
return Err(custom_err!("must have at least one non-generated column"));
}

if options.contains(TableOptions::STRICT) {
for c in columns {
Expand Down

0 comments on commit bcfea15

Please sign in to comment.