@@ -17,6 +17,7 @@ package queries
1717import (
1818 "github.com/dolthub/go-mysql-server/sql"
1919 "github.com/dolthub/go-mysql-server/sql/types"
20+ "time"
2021)
2122
2223var ViewScripts = []ScriptTest {
@@ -364,6 +365,47 @@ var ViewCreateInSubroutineTests = []ScriptTest{
364365 },
365366 },
366367 },
368+ {
369+ // https://github.com/dolthub/dolt/issues/9738
370+ Name : "CREATE VIEW with parentheses around SELECT" ,
371+ SetUpScript : []string {
372+ "CREATE TABLE test_table (id INT, name VARCHAR(50), active BOOLEAN);" ,
373+ "INSERT INTO test_table VALUES (1, 'Alice', true), (2, 'Bob', false), (3, 'Charlie', true);" ,
374+ "CREATE TABLE task_history (id INT, task VARCHAR(100), db_id INT, started_at DATETIME, ended_at DATETIME, duration INT, task_details TEXT);" ,
375+ "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');" ,
376+ },
377+ Assertions : []ScriptTestAssertion {
378+ {
379+ Query : "CREATE VIEW simple_view AS (SELECT id, name FROM test_table WHERE active = true);" ,
380+ Expected : []sql.Row {
381+ {types .NewOkResult (0 )},
382+ },
383+ },
384+ {
385+ Query : "SELECT * FROM simple_view ORDER BY id;" ,
386+ Expected : []sql.Row {{1 , "Alice" }, {3 , "Charlie" }},
387+ },
388+ {
389+ Query : "CREATE VIEW complex_view AS (SELECT id, name, CONCAT('user_', id) AS user_id FROM test_table WHERE active = true);" ,
390+ Expected : []sql.Row {
391+ {types .NewOkResult (0 )},
392+ },
393+ },
394+ {
395+ Query : "SELECT * FROM complex_view ORDER BY id;" ,
396+ Expected : []sql.Row {{1 , "Alice" , "user_1" }, {3 , "Charlie" , "user_3" }},
397+ },
398+ {
399+ 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);" ,
400+ Expected : []sql.Row {
401+ {types .NewOkResult (0 )},
402+ },
403+ },
404+ {
405+ Query : "SELECT * FROM v_tasks ORDER BY id;" ,
406+ 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" }},
407+ }},
408+ },
367409 {
368410 Name : "trigger contains CREATE VIEW AS" ,
369411 SetUpScript : []string {
0 commit comments