diff --git a/src/sql/src/parsers/alter_parser.rs b/src/sql/src/parsers/alter_parser.rs index 03aa63b66e0e..f590b4cf3ede 100644 --- a/src/sql/src/parsers/alter_parser.rs +++ b/src/sql/src/parsers/alter_parser.rs @@ -320,7 +320,9 @@ mod tests { ParserContext::create_with_dialect(sql, &GreptimeDbDialect {}, ParseOptions::default()) .unwrap_err(); let err = result.output_msg(); - assert!(err.contains("expect keyword ADD or DROP or ALERT COLUMN or RENAME after ALTER TABLE")); + assert!( + err.contains("expect keyword ADD or DROP or ALERT COLUMN or RENAME after ALTER TABLE") + ); let sql = "ALTER TABLE test_table RENAME table_t"; let mut result = diff --git a/tests/cases/standalone/common/alter/modify_col.result b/tests/cases/standalone/common/alter/modify_col.result index 8eb1f5cc8a0f..668527131e6a 100644 --- a/tests/cases/standalone/common/alter/modify_col.result +++ b/tests/cases/standalone/common/alter/modify_col.result @@ -1,8 +1,8 @@ -CREATE TABLE test(i INTEGER, j TIMESTAMP TIME INDEX); +CREATE TABLE test(id INTEGER PRIMARY KEY, i INTEGER, j TIMESTAMP TIME INDEX, k BOOLEAN); Affected Rows: 0 -INSERT INTO test VALUES (1, 1), (2, 2); +INSERT INTO test VALUES (1, 1, 1, false), (2, 2, 2, true); Affected Rows: 2 @@ -10,30 +10,40 @@ ALTER TABLE test ALTER COLUMN "I" TYPE STRING; Error: 4002(TableColumnNotFound), Column I not exists in table test -ALTER TABLE test ALTER COLUMN I TYPE STRING; +ALTER TABLE test ALTER COLUMN k TYPE DATE; -Affected Rows: 0 +Error: 1004(InvalidArguments), Invalid alter table(test) request: column 'k' cannot be cast automatically to type 'Date' -SELECT * FROM test; +ALTER TABLE test ALTER COLUMN id TYPE STRING; -+---+-------------------------+ -| i | j | -+---+-------------------------+ -| 1 | 1970-01-01T00:00:00.001 | -| 2 | 1970-01-01T00:00:00.002 | -+---+-------------------------+ +Error: 1004(InvalidArguments), Not allowed to modify index column id from table test ALTER TABLE test ALTER COLUMN j TYPE STRING; Error: 1004(InvalidArguments), Not allowed to modify index column j from table test +ALTER TABLE test ALTER COLUMN I TYPE STRING; + +Affected Rows: 0 + +SELECT * FROM test; + ++----+---+-------------------------+-------+ +| id | i | j | k | ++----+---+-------------------------+-------+ +| 1 | 1 | 1970-01-01T00:00:00.001 | false | +| 2 | 2 | 1970-01-01T00:00:00.002 | true | ++----+---+-------------------------+-------+ + DESCRIBE test; +--------+----------------------+-----+------+---------+---------------+ | Column | Type | Key | Null | Default | Semantic Type | +--------+----------------------+-----+------+---------+---------------+ +| id | Int32 | PRI | YES | | TAG | | i | String | | YES | | FIELD | | j | TimestampMillisecond | PRI | NO | | TIMESTAMP | +| k | Boolean | | YES | | FIELD | +--------+----------------------+-----+------+---------+---------------+ DROP TABLE test; diff --git a/tests/cases/standalone/common/alter/modify_col.sql b/tests/cases/standalone/common/alter/modify_col.sql index 1ed2428b6b6a..b3d1006689ec 100644 --- a/tests/cases/standalone/common/alter/modify_col.sql +++ b/tests/cases/standalone/common/alter/modify_col.sql @@ -1,15 +1,19 @@ -CREATE TABLE test(i INTEGER, j TIMESTAMP TIME INDEX); +CREATE TABLE test(id INTEGER PRIMARY KEY, i INTEGER, j TIMESTAMP TIME INDEX, k BOOLEAN); -INSERT INTO test VALUES (1, 1), (2, 2); +INSERT INTO test VALUES (1, 1, 1, false), (2, 2, 2, true); ALTER TABLE test ALTER COLUMN "I" TYPE STRING; -ALTER TABLE test ALTER COLUMN I TYPE STRING; +ALTER TABLE test ALTER COLUMN k TYPE DATE; -SELECT * FROM test; +ALTER TABLE test ALTER COLUMN id TYPE STRING; ALTER TABLE test ALTER COLUMN j TYPE STRING; +ALTER TABLE test ALTER COLUMN I TYPE STRING; + +SELECT * FROM test; + DESCRIBE test; -DROP TABLE test; \ No newline at end of file +DROP TABLE test; diff --git a/tests/cases/standalone/common/alter/modify_col_not_null.sql b/tests/cases/standalone/common/alter/modify_col_not_null.sql index 3835f2d5e0f6..28075c658f18 100644 --- a/tests/cases/standalone/common/alter/modify_col_not_null.sql +++ b/tests/cases/standalone/common/alter/modify_col_not_null.sql @@ -12,4 +12,4 @@ SELECT * FROM test; DESCRIBE test; -DROP TABLE test; \ No newline at end of file +DROP TABLE test;