|
15 | 15 | package queries |
16 | 16 |
|
17 | 17 | import ( |
| 18 | + "time" |
| 19 | + |
18 | 20 | "github.com/dolthub/go-mysql-server/sql" |
19 | 21 | "github.com/dolthub/go-mysql-server/sql/types" |
20 | 22 | ) |
@@ -364,6 +366,47 @@ var ViewCreateInSubroutineTests = []ScriptTest{ |
364 | 366 | }, |
365 | 367 | }, |
366 | 368 | }, |
| 369 | + { |
| 370 | + // https://github.com/dolthub/dolt/issues/9738 |
| 371 | + Name: "CREATE VIEW with parentheses around SELECT", |
| 372 | + SetUpScript: []string{ |
| 373 | + "CREATE TABLE test_table (id INT, name VARCHAR(50), active BOOLEAN);", |
| 374 | + "INSERT INTO test_table VALUES (1, 'Alice', true), (2, 'Bob', false), (3, 'Charlie', true);", |
| 375 | + "CREATE TABLE task_history (id INT, task VARCHAR(100), db_id INT, started_at DATETIME, ended_at DATETIME, duration INT, task_details TEXT);", |
| 376 | + "INSERT INTO task_history VALUES (1, 'Task 1', 1, '2023-01-01 10:00:00', '2023-01-01 11:00:00', 3600000, 'Task details 1'), (2, 'Task 2', 2, '2023-01-02 10:00:00', '2023-01-02 12:00:00', 7200000, 'Task details 2');", |
| 377 | + }, |
| 378 | + Assertions: []ScriptTestAssertion{ |
| 379 | + { |
| 380 | + Query: "CREATE VIEW simple_view AS (SELECT id, name FROM test_table WHERE active = true);", |
| 381 | + Expected: []sql.Row{ |
| 382 | + {types.NewOkResult(0)}, |
| 383 | + }, |
| 384 | + }, |
| 385 | + { |
| 386 | + Query: "SELECT * FROM simple_view ORDER BY id;", |
| 387 | + Expected: []sql.Row{{1, "Alice"}, {3, "Charlie"}}, |
| 388 | + }, |
| 389 | + { |
| 390 | + Query: "CREATE VIEW complex_view AS (SELECT id, name, CONCAT('user_', id) AS user_id FROM test_table WHERE active = true);", |
| 391 | + Expected: []sql.Row{ |
| 392 | + {types.NewOkResult(0)}, |
| 393 | + }, |
| 394 | + }, |
| 395 | + { |
| 396 | + Query: "SELECT * FROM complex_view ORDER BY id;", |
| 397 | + Expected: []sql.Row{{1, "Alice", "user_1"}, {3, "Charlie", "user_3"}}, |
| 398 | + }, |
| 399 | + { |
| 400 | + Query: "CREATE OR REPLACE VIEW v_tasks AS (SELECT id, task, CONCAT('database_', db_id) AS database_qualified_id, started_at, ended_at, CAST(duration AS DOUBLE) / 1000 AS duration_seconds, task_details AS details FROM task_history);", |
| 401 | + Expected: []sql.Row{ |
| 402 | + {types.NewOkResult(0)}, |
| 403 | + }, |
| 404 | + }, |
| 405 | + { |
| 406 | + Query: "SELECT * FROM v_tasks ORDER BY id;", |
| 407 | + Expected: []sql.Row{{1, "Task 1", "database_1", time.Date(2023, time.January, 1, 10, 0, 0, 0, time.UTC), time.Date(2023, time.January, 1, 11, 0, 0, 0, time.UTC), 3600.0, "Task details 1"}, {2, "Task 2", "database_2", time.Date(2023, time.January, 2, 10, 0, 0, 0, time.UTC), time.Date(2023, time.January, 2, 12, 0, 0, 0, time.UTC), 7200.0, "Task details 2"}}, |
| 408 | + }}, |
| 409 | + }, |
367 | 410 | { |
368 | 411 | Name: "trigger contains CREATE VIEW AS", |
369 | 412 | SetUpScript: []string{ |
|
0 commit comments