diff --git a/embedded/sql/catalog.go b/embedded/sql/catalog.go index 7afbe87d53..5326d5987a 100644 --- a/embedded/sql/catalog.go +++ b/embedded/sql/catalog.go @@ -478,13 +478,36 @@ func (t *Table) newColumn(spec *ColSpec) (*Column, error) { return col, nil } +func (ctlg *Catalog) renameTable(oldName, newName string) (*Table, error) { + if oldName == newName { + return nil, fmt.Errorf("%w (%s)", ErrSameOldAndNewNames, oldName) + } + + t, err := ctlg.GetTableByName(oldName) + if err != nil { + return nil, err + } + + _, err = ctlg.GetTableByName(newName) + if err == nil { + return nil, fmt.Errorf("%w (%s)", ErrTableAlreadyExists, newName) + } + + t.name = newName + + delete(ctlg.tablesByName, oldName) + ctlg.tablesByName[newName] = t + + return t, nil +} + func (t *Table) renameColumn(oldName, newName string) (*Column, error) { if newName == revCol { return nil, fmt.Errorf("%w(%s)", ErrReservedWord, revCol) } if oldName == newName { - return nil, fmt.Errorf("%w (%s)", ErrSameOldAndNewColumnName, oldName) + return nil, fmt.Errorf("%w (%s)", ErrSameOldAndNewNames, oldName) } col, exists := t.colsByName[oldName] diff --git a/embedded/sql/engine.go b/embedded/sql/engine.go index ec7ec68445..50fa1ba7af 100644 --- a/embedded/sql/engine.go +++ b/embedded/sql/engine.go @@ -39,7 +39,7 @@ var ErrTableDoesNotExist = errors.New("table does not exist") var ErrColumnDoesNotExist = errors.New("column does not exist") var ErrColumnAlreadyExists = errors.New("column already exists") var ErrCantDropIndexedColumn = errors.New("can not drop indexed column") -var ErrSameOldAndNewColumnName = errors.New("same old and new column names") +var ErrSameOldAndNewNames = errors.New("same old and new names") var ErrColumnNotIndexed = errors.New("column is not indexed") var ErrFunctionDoesNotExist = errors.New("function does not exist") var ErrLimitedKeyType = errors.New("indexed key of unsupported type or exceeded length") diff --git a/embedded/sql/engine_test.go b/embedded/sql/engine_test.go index 1ba6082282..e3eef150f7 100644 --- a/embedded/sql/engine_test.go +++ b/embedded/sql/engine_test.go @@ -1097,7 +1097,7 @@ func TestAddColumn(t *testing.T) { }) } -func TestRenameColumn(t *testing.T) { +func TestRenaming(t *testing.T) { dir := t.TempDir() t.Run("create-store", func(t *testing.T) { @@ -1108,17 +1108,23 @@ func TestRenameColumn(t *testing.T) { engine, err := NewEngine(st, DefaultOptions().WithPrefix(sqlPrefix)) require.NoError(t, err) - _, _, err = engine.Exec(context.Background(), nil, "CREATE TABLE table1 (id INTEGER AUTO_INCREMENT, name VARCHAR[50], PRIMARY KEY id)", nil) + _, _, err = engine.Exec(context.Background(), nil, "ALTER TABLE table1 RENAME TO table11", nil) + require.ErrorIs(t, err, ErrTableDoesNotExist) + + _, _, err = engine.Exec(context.Background(), nil, "CREATE TABLE table11 (id INTEGER AUTO_INCREMENT, name VARCHAR[50], PRIMARY KEY id)", nil) require.NoError(t, err) - _, _, err = engine.Exec(context.Background(), nil, "CREATE INDEX ON table1(name)", nil) + _, _, err = engine.Exec(context.Background(), nil, "CREATE INDEX ON table11(name)", nil) + require.NoError(t, err) + + _, _, err = engine.Exec(context.Background(), nil, "ALTER TABLE table11 RENAME TO table1", nil) require.NoError(t, err) _, _, err = engine.Exec(context.Background(), nil, "INSERT INTO table1(name) VALUES('John'), ('Sylvia'), ('Robocop') ", nil) require.NoError(t, err) _, _, err = engine.Exec(context.Background(), nil, "ALTER TABLE table1 RENAME COLUMN name TO name", nil) - require.ErrorIs(t, err, ErrSameOldAndNewColumnName) + require.ErrorIs(t, err, ErrSameOldAndNewNames) _, _, err = engine.Exec(context.Background(), nil, "ALTER TABLE table1 RENAME COLUMN name TO id", nil) require.ErrorIs(t, err, ErrColumnAlreadyExists) @@ -1168,7 +1174,13 @@ func TestRenameColumn(t *testing.T) { engine, err := NewEngine(st, DefaultOptions().WithPrefix(sqlPrefix)) require.NoError(t, err) - res, err := engine.Query(context.Background(), nil, "SELECT id, surname FROM table1 ORDER BY surname", nil) + _, _, err = engine.Exec(context.Background(), nil, "ALTER TABLE table1 RENAME TO table1", nil) + require.ErrorIs(t, err, ErrSameOldAndNewNames) + + _, _, err = engine.Exec(context.Background(), nil, "ALTER TABLE table1 RENAME TO table11", nil) + require.NoError(t, err) + + res, err := engine.Query(context.Background(), nil, "SELECT id, surname FROM table11 ORDER BY surname", nil) require.NoError(t, err) row, err := res.Read(context.Background()) @@ -4188,6 +4200,9 @@ func TestJoins(t *testing.T) { _, _, err = engine.Exec(context.Background(), nil, "CREATE TABLE table3 (id INTEGER, age INTEGER, PRIMARY KEY id)", nil) require.NoError(t, err) + _, _, err = engine.Exec(context.Background(), nil, "ALTER TABLE table1 RENAME TO table3", nil) + require.ErrorIs(t, err, ErrTableAlreadyExists) + rowCount := 10 for i := 0; i < rowCount; i++ { diff --git a/embedded/sql/sql_grammar.y b/embedded/sql/sql_grammar.y index e13ded5b3c..eb78b008e5 100644 --- a/embedded/sql/sql_grammar.y +++ b/embedded/sql/sql_grammar.y @@ -240,6 +240,11 @@ ddlstmt: { $$ = &AddColumnStmt{table: $3, colSpec: $6} } +| + ALTER TABLE IDENTIFIER RENAME TO IDENTIFIER + { + $$ = &RenameTableStmt{oldName: $3, newName: $6} + } | ALTER TABLE IDENTIFIER RENAME COLUMN IDENTIFIER TO IDENTIFIER { diff --git a/embedded/sql/sql_parser.go b/embedded/sql/sql_parser.go index 1dd244420e..069d296943 100644 --- a/embedded/sql/sql_parser.go +++ b/embedded/sql/sql_parser.go @@ -243,146 +243,146 @@ var yyExca = [...]int16{ 1, -1, -2, 0, -1, 80, - 59, 145, - 62, 145, - -2, 133, - -1, 203, - 45, 109, - -2, 104, - -1, 234, - 45, 109, - -2, 106, + 59, 146, + 62, 146, + -2, 134, + -1, 205, + 45, 110, + -2, 105, + -1, 236, + 45, 110, + -2, 107, } const yyPrivate = 57344 -const yyLast = 403 +const yyLast = 405 var yyAct = [...]int16{ - 79, 318, 66, 197, 115, 227, 152, 253, 257, 94, - 158, 149, 187, 233, 107, 252, 6, 188, 169, 48, - 85, 110, 289, 244, 195, 243, 221, 195, 19, 195, - 195, 195, 294, 300, 274, 272, 293, 245, 222, 196, - 290, 258, 284, 275, 82, 273, 238, 84, 220, 78, - 162, 97, 93, 218, 95, 96, 210, 209, 259, 98, - 65, 88, 89, 90, 91, 92, 67, 160, 133, 194, - 119, 83, 254, 217, 214, 142, 87, 112, 142, 126, - 171, 143, 141, 137, 138, 139, 121, 118, 140, 127, - 128, 130, 129, 82, 106, 21, 84, 105, 108, 317, - 97, 93, 311, 95, 96, 277, 68, 278, 98, 154, - 88, 89, 90, 91, 92, 67, 119, 133, 151, 165, - 83, 166, 133, 161, 155, 87, 132, 221, 173, 174, - 175, 176, 177, 178, 156, 163, 211, 68, 127, 128, - 130, 129, 186, 189, 67, 130, 129, 68, 195, 114, - 63, 101, 133, 271, 67, 190, 184, 270, 202, 249, - 131, 132, 200, 133, 191, 203, 207, 240, 208, 77, - 277, 131, 132, 127, 128, 130, 129, 205, 201, 204, - 185, 219, 216, 213, 127, 128, 130, 129, 117, 133, - 28, 29, 212, 183, 68, 150, 53, 131, 132, 229, - 265, 251, 225, 111, 231, 193, 116, 192, 170, 237, - 127, 128, 130, 129, 170, 172, 167, 164, 189, 144, - 122, 99, 250, 100, 71, 69, 246, 37, 55, 256, - 241, 52, 47, 157, 247, 248, 236, 260, 288, 215, - 120, 287, 255, 264, 136, 124, 125, 261, 262, 54, - 269, 180, 133, 135, 43, 189, 27, 268, 179, 181, - 70, 61, 182, 38, 319, 320, 303, 279, 228, 198, - 310, 280, 297, 161, 283, 285, 282, 42, 108, 296, - 263, 113, 35, 206, 40, 291, 19, 308, 301, 299, - 298, 292, 59, 226, 224, 34, 33, 304, 22, 266, - 306, 147, 44, 45, 146, 145, 309, 223, 312, 307, - 230, 123, 72, 315, 316, 313, 19, 199, 82, 2, - 321, 84, 46, 322, 73, 97, 93, 32, 95, 96, - 10, 12, 11, 98, 104, 88, 89, 90, 91, 92, - 67, 41, 159, 239, 30, 83, 31, 13, 76, 75, - 87, 102, 103, 153, 7, 23, 8, 9, 14, 15, - 36, 20, 16, 17, 276, 24, 26, 25, 19, 50, - 51, 109, 134, 267, 286, 302, 56, 57, 58, 314, - 242, 281, 81, 80, 295, 235, 234, 232, 74, 49, - 60, 39, 64, 62, 86, 305, 148, 168, 18, 5, - 4, 3, 1, + 79, 320, 66, 199, 115, 229, 153, 255, 259, 94, + 159, 150, 188, 235, 107, 254, 6, 189, 170, 48, + 85, 110, 291, 246, 197, 245, 223, 197, 19, 197, + 197, 197, 296, 302, 276, 274, 295, 247, 224, 198, + 292, 260, 286, 277, 82, 275, 240, 84, 222, 78, + 163, 97, 93, 220, 95, 96, 212, 211, 261, 98, + 65, 88, 89, 90, 91, 92, 67, 161, 133, 196, + 119, 83, 256, 219, 216, 142, 87, 112, 142, 126, + 172, 143, 141, 137, 138, 139, 121, 118, 140, 127, + 128, 130, 129, 82, 106, 21, 84, 105, 280, 319, + 97, 93, 313, 95, 96, 279, 68, 223, 98, 155, + 88, 89, 90, 91, 92, 67, 108, 133, 152, 166, + 83, 167, 133, 162, 156, 87, 132, 213, 174, 175, + 176, 177, 178, 179, 197, 164, 114, 68, 127, 128, + 130, 129, 187, 190, 67, 130, 129, 119, 101, 133, + 63, 273, 157, 68, 272, 191, 185, 131, 132, 204, + 67, 279, 251, 202, 192, 242, 205, 209, 214, 210, + 127, 128, 130, 129, 117, 77, 184, 186, 207, 203, + 206, 53, 68, 218, 215, 151, 221, 28, 29, 267, + 253, 227, 116, 111, 133, 195, 194, 193, 171, 173, + 168, 231, 131, 132, 120, 165, 233, 144, 122, 100, + 71, 239, 171, 69, 37, 127, 128, 130, 129, 55, + 190, 52, 47, 158, 252, 238, 136, 99, 248, 290, + 217, 258, 243, 289, 54, 135, 249, 250, 133, 262, + 133, 271, 43, 70, 257, 266, 131, 132, 270, 263, + 264, 124, 125, 27, 61, 182, 181, 190, 183, 127, + 128, 130, 129, 180, 38, 321, 322, 305, 230, 281, + 200, 312, 299, 282, 284, 162, 285, 287, 108, 42, + 298, 265, 113, 35, 40, 208, 19, 293, 310, 303, + 294, 301, 300, 59, 228, 226, 22, 34, 33, 306, + 268, 225, 308, 148, 44, 45, 146, 147, 311, 145, + 314, 309, 232, 123, 72, 317, 318, 315, 19, 201, + 82, 2, 323, 84, 46, 324, 73, 97, 93, 32, + 95, 96, 10, 12, 11, 98, 104, 88, 89, 90, + 91, 92, 67, 41, 160, 241, 30, 83, 31, 13, + 76, 75, 87, 102, 103, 154, 7, 23, 8, 9, + 14, 15, 36, 20, 16, 17, 278, 24, 26, 25, + 19, 50, 51, 109, 134, 269, 288, 304, 56, 57, + 58, 316, 244, 283, 81, 80, 297, 237, 236, 234, + 74, 49, 60, 39, 64, 62, 86, 307, 149, 169, + 18, 5, 4, 3, 1, } var yyPact = [...]int16{ - 326, -1000, -1000, 6, -1000, -1000, -1000, 269, -1000, -1000, - 348, 183, 327, 310, 262, 261, 238, 154, 207, 241, - -1000, 326, -1000, 194, 194, 194, 303, -1000, 159, 359, - 158, 176, 155, 154, 154, 154, 254, -1000, 204, 64, - -1000, -1000, 152, 202, 151, 292, 194, -1000, -1000, 336, - 35, 35, -1000, 150, 69, 329, 7, 4, 231, 130, - 244, -1000, 237, -1000, 66, 133, -1000, -3, 34, -1000, - 179, -4, 147, 291, -1000, 35, 35, -1000, 260, 100, - 186, -1000, 260, 260, -5, -1000, -1000, 260, -1000, -1000, + 328, -1000, -1000, 6, -1000, -1000, -1000, 267, -1000, -1000, + 350, 180, 329, 312, 264, 263, 239, 141, 208, 241, + -1000, 328, -1000, 182, 182, 182, 305, -1000, 149, 361, + 148, 161, 146, 141, 141, 141, 255, -1000, 197, 64, + -1000, -1000, 140, 185, 137, 294, 182, -1000, -1000, 338, + 35, 35, -1000, 136, 66, 331, 7, 4, 231, 120, + 244, -1000, 238, -1000, 53, 119, -1000, -3, 65, -1000, + 143, -4, 135, 293, -1000, 35, 35, -1000, 262, 175, + 168, -1000, 262, 262, -5, -1000, -1000, 262, -1000, -1000, -1000, -1000, -1000, -8, -1000, -1000, -1000, -1000, -12, -1000, - -9, 146, 280, 279, 276, 122, 122, 347, 260, 51, - -1000, 161, -1000, -23, 74, -1000, -1000, 144, 33, 143, - -1000, 135, -10, 142, -1000, -1000, 100, 260, 260, 260, - 260, 260, 260, 193, 200, 119, -1000, 54, 59, 244, - 89, 260, 260, 122, -1000, 135, 134, 132, -22, 65, - -1000, -52, 219, 298, 100, 347, 130, 260, 347, 359, - 274, 133, -15, 133, -1000, -34, -35, -1000, 53, -1000, - 118, 122, -16, 59, 59, 189, 189, 54, 5, -1000, - 174, 260, -17, -1000, -38, -1000, 126, -43, 44, 100, - -53, -1000, 283, -1000, 259, 129, 258, 217, 260, 290, - 219, -1000, 100, 166, 133, -45, 328, -1000, -1000, -1000, - -1000, 141, -67, -54, 122, -1000, 54, -14, -1000, 85, - -1000, 260, -1000, 128, -18, -1000, -18, -1000, 260, 100, - -32, 217, 231, -1000, 166, 235, -1000, -1000, 133, 127, - 272, -1000, 192, 82, 78, -1000, -56, -46, -57, -48, - 100, -1000, 87, -1000, 260, 22, 100, -1000, -1000, 122, - -1000, 228, -1000, -23, -1000, -49, -32, 177, -1000, 173, - -71, -51, -1000, -1000, -1000, -1000, -1000, -18, 252, -55, - -59, 233, 223, 347, 133, -58, -1000, -1000, -1000, -1000, - -1000, -1000, 248, -1000, -1000, 214, 260, 121, 289, -1000, - -1000, 246, 219, 221, 100, 19, -1000, 260, -1000, 217, - 121, 121, 100, -1000, 16, 211, -1000, 121, -1000, -1000, - -1000, 211, -1000, + -9, 134, 284, 282, 278, 112, 112, 349, 262, 69, + -1000, 151, -1000, -23, 80, -1000, -1000, 132, 33, 127, + -1000, 125, -10, 126, -1000, -1000, 175, 262, 262, 262, + 262, 262, 262, 198, 196, 102, -1000, 54, 59, 244, + 86, 262, 262, 112, -1000, 125, 124, 123, 122, -22, + 51, -1000, -52, 220, 300, 175, 349, 120, 262, 349, + 361, 276, 119, -15, 119, -1000, -34, -35, -1000, 44, + -1000, 94, 112, -16, 59, 59, 177, 177, 54, 5, + -1000, 165, 262, -17, -1000, -38, -1000, 131, -43, 24, + 175, -53, -1000, -1000, 277, -1000, 260, 118, 259, 217, + 262, 292, 220, -1000, 175, 155, 119, -45, 330, -1000, + -1000, -1000, -1000, 139, -67, -54, 112, -1000, 54, -14, + -1000, 88, -1000, 262, -1000, 117, -18, -1000, -18, -1000, + 262, 175, -32, 217, 231, -1000, 155, 236, -1000, -1000, + 119, 116, 273, -1000, 183, 79, 76, -1000, -56, -46, + -57, -48, 175, -1000, 78, -1000, 262, 22, 175, -1000, + -1000, 112, -1000, 226, -1000, -23, -1000, -49, -32, 169, + -1000, 164, -71, -51, -1000, -1000, -1000, -1000, -1000, -18, + 251, -55, -59, 234, 223, 349, 119, -58, -1000, -1000, + -1000, -1000, -1000, -1000, 249, -1000, -1000, 215, 262, 109, + 291, -1000, -1000, 247, 220, 222, 175, 19, -1000, 262, + -1000, 217, 109, 109, 175, -1000, 16, 212, -1000, 109, + -1000, -1000, -1000, 212, -1000, } var yyPgo = [...]int16{ - 0, 402, 319, 401, 400, 399, 16, 398, 397, 18, - 11, 8, 396, 395, 15, 7, 17, 12, 394, 9, - 20, 393, 392, 2, 391, 390, 10, 342, 19, 389, - 388, 169, 387, 13, 386, 385, 0, 14, 384, 383, - 382, 381, 3, 5, 380, 4, 379, 375, 1, 6, - 277, 374, 373, 372, 21, 371, 364, 361, + 0, 404, 321, 403, 402, 401, 16, 400, 399, 18, + 11, 8, 398, 397, 15, 7, 17, 12, 396, 9, + 20, 395, 394, 2, 393, 392, 10, 344, 19, 391, + 390, 175, 389, 13, 388, 387, 0, 14, 386, 385, + 384, 383, 3, 5, 382, 4, 381, 377, 1, 6, + 279, 376, 375, 374, 21, 373, 366, 363, } var yyR1 = [...]int8{ 0, 1, 2, 2, 57, 57, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 4, 4, 4, 4, 4, 4, 50, 50, 11, 11, - 5, 5, 5, 5, 56, 56, 55, 55, 54, 12, - 12, 14, 14, 15, 10, 10, 13, 13, 17, 17, - 16, 16, 18, 18, 18, 18, 18, 18, 18, 18, - 18, 18, 19, 8, 8, 9, 44, 44, 44, 51, - 51, 52, 52, 52, 6, 6, 7, 25, 25, 24, - 24, 21, 21, 22, 22, 20, 20, 20, 23, 23, - 26, 26, 26, 26, 27, 28, 29, 29, 29, 30, - 30, 30, 31, 31, 32, 32, 33, 33, 34, 35, - 35, 37, 37, 41, 41, 38, 38, 42, 42, 43, - 43, 47, 47, 49, 49, 46, 46, 48, 48, 48, - 45, 45, 45, 36, 36, 36, 36, 36, 36, 36, - 36, 39, 39, 39, 39, 53, 53, 40, 40, 40, - 40, 40, 40, 40, 40, + 4, 4, 4, 4, 4, 4, 4, 50, 50, 11, + 11, 5, 5, 5, 5, 56, 56, 55, 55, 54, + 12, 12, 14, 14, 15, 10, 10, 13, 13, 17, + 17, 16, 16, 18, 18, 18, 18, 18, 18, 18, + 18, 18, 18, 19, 8, 8, 9, 44, 44, 44, + 51, 51, 52, 52, 52, 6, 6, 7, 25, 25, + 24, 24, 21, 21, 22, 22, 20, 20, 20, 23, + 23, 26, 26, 26, 26, 27, 28, 29, 29, 29, + 30, 30, 30, 31, 31, 32, 32, 33, 33, 34, + 35, 35, 37, 37, 41, 41, 38, 38, 42, 42, + 43, 43, 47, 47, 49, 49, 46, 46, 48, 48, + 48, 45, 45, 45, 36, 36, 36, 36, 36, 36, + 36, 36, 39, 39, 39, 39, 53, 53, 40, 40, + 40, 40, 40, 40, 40, 40, } var yyR2 = [...]int8{ 0, 1, 2, 3, 0, 1, 1, 1, 1, 2, 1, 1, 1, 4, 2, 3, 3, 11, 3, 8, - 9, 7, 5, 6, 8, 6, 0, 3, 1, 3, - 9, 8, 7, 8, 0, 4, 1, 3, 3, 0, - 1, 1, 3, 3, 1, 3, 1, 3, 0, 1, - 1, 3, 1, 1, 1, 1, 1, 6, 1, 1, - 1, 1, 4, 1, 3, 5, 0, 3, 3, 0, - 1, 0, 1, 2, 1, 4, 13, 0, 1, 0, - 1, 1, 1, 2, 4, 1, 4, 4, 1, 3, - 3, 4, 2, 6, 1, 2, 0, 2, 2, 0, - 2, 2, 2, 1, 0, 1, 1, 2, 6, 0, - 1, 0, 2, 0, 3, 0, 2, 0, 2, 0, - 2, 0, 3, 0, 4, 2, 4, 0, 1, 1, - 0, 1, 2, 1, 1, 2, 2, 4, 4, 6, - 6, 1, 1, 3, 3, 0, 1, 3, 3, 3, - 3, 3, 3, 3, 4, + 9, 7, 5, 6, 6, 8, 6, 0, 3, 1, + 3, 9, 8, 7, 8, 0, 4, 1, 3, 3, + 0, 1, 1, 3, 3, 1, 3, 1, 3, 0, + 1, 1, 3, 1, 1, 1, 1, 1, 6, 1, + 1, 1, 1, 4, 1, 3, 5, 0, 3, 3, + 0, 1, 0, 1, 2, 1, 4, 13, 0, 1, + 0, 1, 1, 1, 2, 4, 1, 4, 4, 1, + 3, 3, 4, 2, 6, 1, 2, 0, 2, 2, + 0, 2, 2, 2, 1, 0, 1, 1, 2, 6, + 0, 1, 0, 2, 0, 3, 0, 2, 0, 2, + 0, 2, 0, 3, 0, 4, 2, 4, 0, 1, + 1, 0, 1, 2, 1, 1, 2, 2, 4, 4, + 6, 6, 1, 1, 3, 3, 0, 1, 3, 3, + 3, 3, 3, 3, 3, 4, } var yyChk = [...]int16{ @@ -400,61 +400,61 @@ var yyChk = [...]int16{ -54, 73, -6, 44, 83, -45, 73, 55, 90, 82, 61, 90, 73, 20, -31, -31, -36, 84, 85, 87, 86, 71, 72, 63, -53, 67, 58, -36, -36, 90, - -36, 90, 90, 90, 73, 25, 25, 25, -12, -10, - 73, -10, -49, 6, -36, -37, 83, 72, -26, -27, - 90, -19, 73, -20, 73, 86, -23, 73, -8, -9, - 73, 90, 73, -36, -36, -36, -36, -36, -36, 65, - 58, 59, 62, 74, -6, 91, -36, -17, -16, -36, - -10, -9, 73, 73, 91, 83, 91, -42, 50, 19, - -49, -54, -36, -49, -28, -6, 9, -45, -45, 91, - 91, 83, 74, -10, 90, 65, -36, 90, 91, 55, - 91, 83, 91, 24, 35, 73, 35, -43, 51, -36, - 20, -42, -32, -33, -34, -35, 70, -45, 91, 15, - 26, -9, -44, 92, 90, 91, -10, -6, -16, 74, - -36, 73, -14, -15, 90, -14, -36, -11, 73, 90, - -43, -37, -33, 45, -45, 73, 27, -52, 65, 58, - 75, 75, 91, 91, 91, 91, -56, 83, 20, -17, - -10, -41, 48, -26, 91, -11, -51, 64, 65, 93, - 91, -15, 39, 91, 91, -38, 46, 49, -49, -45, - 91, 40, -47, 52, -36, -13, -23, 20, 41, -42, - 49, 83, -36, -43, -46, -23, -23, 83, -48, 53, - 54, -23, -48, + -36, 90, 90, 90, 73, 25, 24, 25, 25, -12, + -10, 73, -10, -49, 6, -36, -37, 83, 72, -26, + -27, 90, -19, 73, -20, 73, 86, -23, 73, -8, + -9, 73, 90, 73, -36, -36, -36, -36, -36, -36, + 65, 58, 59, 62, 74, -6, 91, -36, -17, -16, + -36, -10, -9, 73, 73, 73, 91, 83, 91, -42, + 50, 19, -49, -54, -36, -49, -28, -6, 9, -45, + -45, 91, 91, 83, 74, -10, 90, 65, -36, 90, + 91, 55, 91, 83, 91, 24, 35, 73, 35, -43, + 51, -36, 20, -42, -32, -33, -34, -35, 70, -45, + 91, 15, 26, -9, -44, 92, 90, 91, -10, -6, + -16, 74, -36, 73, -14, -15, 90, -14, -36, -11, + 73, 90, -43, -37, -33, 45, -45, 73, 27, -52, + 65, 58, 75, 75, 91, 91, 91, 91, -56, 83, + 20, -17, -10, -41, 48, -26, 91, -11, -51, 64, + 65, 93, 91, -15, 39, 91, 91, -38, 46, 49, + -49, -45, 91, 40, -47, 52, -36, -13, -23, 20, + 41, -42, 49, 83, -36, -43, -46, -23, -23, 83, + -48, 53, 54, -23, -48, } var yyDef = [...]int16{ 0, -2, 1, 4, 6, 7, 8, 10, 11, 12, - 0, 0, 0, 0, 0, 0, 0, 0, 74, 79, - 2, 5, 9, 26, 26, 26, 0, 14, 0, 96, - 0, 0, 0, 0, 0, 0, 0, 94, 77, 0, - 80, 3, 0, 0, 0, 0, 26, 15, 16, 99, - 0, 0, 18, 0, 0, 0, 0, 0, 111, 0, - 0, 78, 0, 81, 82, 130, 85, 0, 88, 13, - 0, 0, 0, 0, 95, 0, 0, 97, 0, 103, - -2, 134, 0, 0, 0, 141, 142, 0, 52, 53, - 54, 55, 56, 0, 58, 59, 60, 61, 88, 98, - 0, 0, 0, 0, 0, 39, 0, 123, 0, 111, - 36, 0, 75, 0, 0, 83, 131, 0, 0, 0, - 27, 0, 0, 0, 100, 101, 102, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 146, 135, 136, 0, - 0, 0, 48, 0, 22, 0, 0, 0, 0, 40, - 44, 0, 117, 0, 112, 123, 0, 0, 123, 96, - 0, 130, 94, 130, 132, 0, 0, 89, 0, 63, - 0, 0, 0, 147, 148, 149, 150, 151, 152, 153, - 0, 0, 0, 144, 0, 143, 0, 0, 49, 50, - 0, 23, 0, 25, 0, 0, 0, 119, 0, 0, - 117, 37, 38, -2, 130, 0, 0, 92, 84, 86, - 87, 0, 66, 0, 0, 154, 137, 0, 138, 0, - 62, 0, 21, 0, 0, 45, 0, 32, 0, 118, - 0, 119, 111, 105, -2, 0, 110, 90, 130, 0, - 0, 64, 71, 0, 0, 19, 0, 0, 0, 0, - 51, 24, 34, 41, 48, 31, 120, 124, 28, 0, - 33, 113, 107, 0, 91, 0, 0, 69, 72, 0, - 0, 0, 20, 139, 140, 57, 30, 0, 0, 0, - 0, 115, 0, 123, 130, 0, 65, 70, 73, 67, - 68, 42, 0, 43, 29, 121, 0, 0, 0, 93, - 17, 0, 117, 0, 116, 114, 46, 0, 35, 119, - 0, 0, 108, 76, 122, 127, 47, 0, 125, 128, - 129, 127, 126, + 0, 0, 0, 0, 0, 0, 0, 0, 75, 80, + 2, 5, 9, 27, 27, 27, 0, 14, 0, 97, + 0, 0, 0, 0, 0, 0, 0, 95, 78, 0, + 81, 3, 0, 0, 0, 0, 27, 15, 16, 100, + 0, 0, 18, 0, 0, 0, 0, 0, 112, 0, + 0, 79, 0, 82, 83, 131, 86, 0, 89, 13, + 0, 0, 0, 0, 96, 0, 0, 98, 0, 104, + -2, 135, 0, 0, 0, 142, 143, 0, 53, 54, + 55, 56, 57, 0, 59, 60, 61, 62, 89, 99, + 0, 0, 0, 0, 0, 40, 0, 124, 0, 112, + 37, 0, 76, 0, 0, 84, 132, 0, 0, 0, + 28, 0, 0, 0, 101, 102, 103, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 147, 136, 137, 0, + 0, 0, 49, 0, 22, 0, 0, 0, 0, 0, + 41, 45, 0, 118, 0, 113, 124, 0, 0, 124, + 97, 0, 131, 95, 131, 133, 0, 0, 90, 0, + 64, 0, 0, 0, 148, 149, 150, 151, 152, 153, + 154, 0, 0, 0, 145, 0, 144, 0, 0, 50, + 51, 0, 23, 24, 0, 26, 0, 0, 0, 120, + 0, 0, 118, 38, 39, -2, 131, 0, 0, 93, + 85, 87, 88, 0, 67, 0, 0, 155, 138, 0, + 139, 0, 63, 0, 21, 0, 0, 46, 0, 33, + 0, 119, 0, 120, 112, 106, -2, 0, 111, 91, + 131, 0, 0, 65, 72, 0, 0, 19, 0, 0, + 0, 0, 52, 25, 35, 42, 49, 32, 121, 125, + 29, 0, 34, 114, 108, 0, 92, 0, 0, 70, + 73, 0, 0, 0, 20, 140, 141, 58, 31, 0, + 0, 0, 0, 116, 0, 124, 131, 0, 66, 71, + 74, 68, 69, 43, 0, 44, 30, 122, 0, 0, + 0, 94, 17, 0, 118, 0, 117, 115, 47, 0, + 36, 120, 0, 0, 109, 77, 123, 128, 48, 0, + 126, 129, 130, 128, 127, } var yyTok1 = [...]int8{ @@ -917,261 +917,266 @@ yydefault: yyVAL.stmt = &AddColumnStmt{table: yyDollar[3].id, colSpec: yyDollar[6].colSpec} } case 24: + yyDollar = yyS[yypt-6 : yypt+1] + { + yyVAL.stmt = &RenameTableStmt{oldName: yyDollar[3].id, newName: yyDollar[6].id} + } + case 25: yyDollar = yyS[yypt-8 : yypt+1] { yyVAL.stmt = &RenameColumnStmt{table: yyDollar[3].id, oldName: yyDollar[6].id, newName: yyDollar[8].id} } - case 25: + case 26: yyDollar = yyS[yypt-6 : yypt+1] { yyVAL.stmt = &DropColumnStmt{table: yyDollar[3].id, colName: yyDollar[6].id} } - case 26: + case 27: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.boolean = false } - case 27: + case 28: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.boolean = true } - case 28: + case 29: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.ids = []string{yyDollar[1].id} } - case 29: + case 30: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.ids = yyDollar[2].ids } - case 30: + case 31: yyDollar = yyS[yypt-9 : yypt+1] { yyVAL.stmt = &UpsertIntoStmt{isInsert: true, tableRef: yyDollar[3].tableRef, cols: yyDollar[5].ids, rows: yyDollar[8].rows, onConflict: yyDollar[9].onConflict} } - case 31: + case 32: yyDollar = yyS[yypt-8 : yypt+1] { yyVAL.stmt = &UpsertIntoStmt{tableRef: yyDollar[3].tableRef, cols: yyDollar[5].ids, rows: yyDollar[8].rows} } - case 32: + case 33: yyDollar = yyS[yypt-7 : yypt+1] { yyVAL.stmt = &DeleteFromStmt{tableRef: yyDollar[3].tableRef, where: yyDollar[4].exp, indexOn: yyDollar[5].ids, limit: yyDollar[6].exp, offset: yyDollar[7].exp} } - case 33: + case 34: yyDollar = yyS[yypt-8 : yypt+1] { yyVAL.stmt = &UpdateStmt{tableRef: yyDollar[2].tableRef, updates: yyDollar[4].updates, where: yyDollar[5].exp, indexOn: yyDollar[6].ids, limit: yyDollar[7].exp, offset: yyDollar[8].exp} } - case 34: + case 35: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.onConflict = nil } - case 35: + case 36: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.onConflict = &OnConflictDo{} } - case 36: + case 37: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.updates = []*colUpdate{yyDollar[1].update} } - case 37: + case 38: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.updates = append(yyDollar[1].updates, yyDollar[3].update) } - case 38: + case 39: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.update = &colUpdate{col: yyDollar[1].id, op: yyDollar[2].cmpOp, val: yyDollar[3].exp} } - case 39: + case 40: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.ids = nil } - case 40: + case 41: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.ids = yyDollar[1].ids } - case 41: + case 42: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.rows = []*RowSpec{yyDollar[1].row} } - case 42: + case 43: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.rows = append(yyDollar[1].rows, yyDollar[3].row) } - case 43: + case 44: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.row = &RowSpec{Values: yyDollar[2].values} } - case 44: + case 45: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.ids = []string{yyDollar[1].id} } - case 45: + case 46: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.ids = append(yyDollar[1].ids, yyDollar[3].id) } - case 46: + case 47: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.cols = []*ColSelector{yyDollar[1].col} } - case 47: + case 48: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.cols = append(yyDollar[1].cols, yyDollar[3].col) } - case 48: + case 49: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.values = nil } - case 49: + case 50: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.values = yyDollar[1].values } - case 50: + case 51: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.values = []ValueExp{yyDollar[1].exp} } - case 51: + case 52: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.values = append(yyDollar[1].values, yyDollar[3].exp) } - case 52: + case 53: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = &Integer{val: int64(yyDollar[1].integer)} } - case 53: + case 54: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = &Float64{val: float64(yyDollar[1].float)} } - case 54: + case 55: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = &Varchar{val: yyDollar[1].str} } - case 55: + case 56: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = &Bool{val: yyDollar[1].boolean} } - case 56: + case 57: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = &Blob{val: yyDollar[1].blob} } - case 57: + case 58: yyDollar = yyS[yypt-6 : yypt+1] { yyVAL.value = &Cast{val: yyDollar[3].exp, t: yyDollar[5].sqlType} } - case 58: + case 59: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = yyDollar[1].value } - case 59: + case 60: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = &Param{id: yyDollar[1].id} } - case 60: + case 61: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = &Param{id: fmt.Sprintf("param%d", yyDollar[1].pparam), pos: yyDollar[1].pparam} } - case 61: + case 62: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.value = &NullValue{t: AnyType} } - case 62: + case 63: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.value = &FnCall{fn: yyDollar[1].id, params: yyDollar[3].values} } - case 63: + case 64: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.colsSpec = []*ColSpec{yyDollar[1].colSpec} } - case 64: + case 65: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.colsSpec = append(yyDollar[1].colsSpec, yyDollar[3].colSpec) } - case 65: + case 66: yyDollar = yyS[yypt-5 : yypt+1] { yyVAL.colSpec = &ColSpec{colName: yyDollar[1].id, colType: yyDollar[2].sqlType, maxLen: int(yyDollar[3].integer), notNull: yyDollar[4].boolean, autoIncrement: yyDollar[5].boolean} } - case 66: + case 67: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.integer = 0 } - case 67: + case 68: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.integer = yyDollar[2].integer } - case 68: + case 69: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.integer = yyDollar[2].integer } - case 69: + case 70: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.boolean = false } - case 70: + case 71: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.boolean = true } - case 71: + case 72: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.boolean = false } - case 72: + case 73: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.boolean = false } - case 73: + case 74: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.boolean = true } - case 74: + case 75: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.stmt = yyDollar[1].stmt } - case 75: + case 76: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.stmt = &UnionStmt{ @@ -1180,7 +1185,7 @@ yydefault: right: yyDollar[4].stmt.(DataSource), } } - case 76: + case 77: yyDollar = yyS[yypt-13 : yypt+1] { yyVAL.stmt = &SelectStmt{ @@ -1197,397 +1202,397 @@ yydefault: offset: yyDollar[13].exp, } } - case 77: + case 78: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.distinct = true } - case 78: + case 79: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.distinct = false } - case 79: + case 80: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.distinct = false } - case 80: + case 81: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.distinct = true } - case 81: + case 82: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.sels = nil } - case 82: + case 83: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.sels = yyDollar[1].sels } - case 83: + case 84: yyDollar = yyS[yypt-2 : yypt+1] { yyDollar[1].sel.setAlias(yyDollar[2].id) yyVAL.sels = []Selector{yyDollar[1].sel} } - case 84: + case 85: yyDollar = yyS[yypt-4 : yypt+1] { yyDollar[3].sel.setAlias(yyDollar[4].id) yyVAL.sels = append(yyDollar[1].sels, yyDollar[3].sel) } - case 85: + case 86: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.sel = yyDollar[1].col } - case 86: + case 87: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.sel = &AggColSelector{aggFn: yyDollar[1].aggFn, col: "*"} } - case 87: + case 88: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.sel = &AggColSelector{aggFn: yyDollar[1].aggFn, table: yyDollar[3].col.table, col: yyDollar[3].col.col} } - case 88: + case 89: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.col = &ColSelector{col: yyDollar[1].id} } - case 89: + case 90: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.col = &ColSelector{table: yyDollar[1].id, col: yyDollar[3].id} } - case 90: + case 91: yyDollar = yyS[yypt-3 : yypt+1] { yyDollar[1].tableRef.period = yyDollar[2].period yyDollar[1].tableRef.as = yyDollar[3].id yyVAL.ds = yyDollar[1].tableRef } - case 91: + case 92: yyDollar = yyS[yypt-4 : yypt+1] { yyDollar[2].stmt.(*SelectStmt).as = yyDollar[4].id yyVAL.ds = yyDollar[2].stmt.(DataSource) } - case 92: + case 93: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.ds = &FnDataSourceStmt{fnCall: yyDollar[1].value.(*FnCall), as: yyDollar[2].id} } - case 93: + case 94: yyDollar = yyS[yypt-6 : yypt+1] { yyVAL.ds = &tableRef{table: yyDollar[4].id, history: true, as: yyDollar[6].id} } - case 94: + case 95: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.tableRef = &tableRef{table: yyDollar[1].id} } - case 95: + case 96: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.period = period{start: yyDollar[1].openPeriod, end: yyDollar[2].openPeriod} } - case 96: + case 97: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.openPeriod = nil } - case 97: + case 98: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.openPeriod = &openPeriod{inclusive: true, instant: yyDollar[2].periodInstant} } - case 98: + case 99: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.openPeriod = &openPeriod{instant: yyDollar[2].periodInstant} } - case 99: + case 100: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.openPeriod = nil } - case 100: + case 101: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.openPeriod = &openPeriod{inclusive: true, instant: yyDollar[2].periodInstant} } - case 101: + case 102: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.openPeriod = &openPeriod{instant: yyDollar[2].periodInstant} } - case 102: + case 103: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.periodInstant = periodInstant{instantType: txInstant, exp: yyDollar[2].exp} } - case 103: + case 104: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.periodInstant = periodInstant{instantType: timeInstant, exp: yyDollar[1].exp} } - case 104: + case 105: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.joins = nil } - case 105: + case 106: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.joins = yyDollar[1].joins } - case 106: + case 107: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.joins = []*JoinSpec{yyDollar[1].join} } - case 107: + case 108: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.joins = append([]*JoinSpec{yyDollar[1].join}, yyDollar[2].joins...) } - case 108: + case 109: yyDollar = yyS[yypt-6 : yypt+1] { yyVAL.join = &JoinSpec{joinType: yyDollar[1].joinType, ds: yyDollar[3].ds, indexOn: yyDollar[4].ids, cond: yyDollar[6].exp} } - case 109: + case 110: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.joinType = InnerJoin } - case 110: + case 111: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.joinType = yyDollar[1].joinType } - case 111: + case 112: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.exp = nil } - case 112: + case 113: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.exp = yyDollar[2].exp } - case 113: + case 114: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.cols = nil } - case 114: + case 115: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.cols = yyDollar[3].cols } - case 115: + case 116: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.exp = nil } - case 116: + case 117: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.exp = yyDollar[2].exp } - case 117: + case 118: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.exp = nil } - case 118: + case 119: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.exp = yyDollar[2].exp } - case 119: + case 120: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.exp = nil } - case 120: + case 121: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.exp = yyDollar[2].exp } - case 121: + case 122: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.ordcols = nil } - case 122: + case 123: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.ordcols = yyDollar[3].ordcols } - case 123: + case 124: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.ids = nil } - case 124: + case 125: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.ids = yyDollar[4].ids } - case 125: + case 126: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.ordcols = []*OrdCol{{sel: yyDollar[1].col, descOrder: yyDollar[2].opt_ord}} } - case 126: + case 127: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.ordcols = append(yyDollar[1].ordcols, &OrdCol{sel: yyDollar[3].col, descOrder: yyDollar[4].opt_ord}) } - case 127: + case 128: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.opt_ord = false } - case 128: + case 129: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.opt_ord = false } - case 129: + case 130: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.opt_ord = true } - case 130: + case 131: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.id = "" } - case 131: + case 132: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.id = yyDollar[1].id } - case 132: + case 133: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.id = yyDollar[2].id } - case 133: + case 134: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.exp = yyDollar[1].exp } - case 134: + case 135: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.exp = yyDollar[1].binExp } - case 135: + case 136: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.exp = &NotBoolExp{exp: yyDollar[2].exp} } - case 136: + case 137: yyDollar = yyS[yypt-2 : yypt+1] { yyVAL.exp = &NumExp{left: &Integer{val: 0}, op: SUBSOP, right: yyDollar[2].exp} } - case 137: + case 138: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.exp = &LikeBoolExp{val: yyDollar[1].exp, notLike: yyDollar[2].boolean, pattern: yyDollar[4].exp} } - case 138: + case 139: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.exp = &ExistsBoolExp{q: (yyDollar[3].stmt).(DataSource)} } - case 139: + case 140: yyDollar = yyS[yypt-6 : yypt+1] { yyVAL.exp = &InSubQueryExp{val: yyDollar[1].exp, notIn: yyDollar[2].boolean, q: yyDollar[5].stmt.(*SelectStmt)} } - case 140: + case 141: yyDollar = yyS[yypt-6 : yypt+1] { yyVAL.exp = &InListExp{val: yyDollar[1].exp, notIn: yyDollar[2].boolean, values: yyDollar[5].values} } - case 141: + case 142: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.exp = yyDollar[1].sel } - case 142: + case 143: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.exp = yyDollar[1].value } - case 143: + case 144: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.exp = yyDollar[2].exp } - case 144: + case 145: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.exp = &Cast{val: yyDollar[1].exp, t: yyDollar[3].sqlType} } - case 145: + case 146: yyDollar = yyS[yypt-0 : yypt+1] { yyVAL.boolean = false } - case 146: + case 147: yyDollar = yyS[yypt-1 : yypt+1] { yyVAL.boolean = true } - case 147: + case 148: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.binExp = &NumExp{left: yyDollar[1].exp, op: ADDOP, right: yyDollar[3].exp} } - case 148: + case 149: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.binExp = &NumExp{left: yyDollar[1].exp, op: SUBSOP, right: yyDollar[3].exp} } - case 149: + case 150: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.binExp = &NumExp{left: yyDollar[1].exp, op: DIVOP, right: yyDollar[3].exp} } - case 150: + case 151: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.binExp = &NumExp{left: yyDollar[1].exp, op: MULTOP, right: yyDollar[3].exp} } - case 151: + case 152: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.binExp = &BinBoolExp{left: yyDollar[1].exp, op: yyDollar[2].logicOp, right: yyDollar[3].exp} } - case 152: + case 153: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.binExp = &CmpBoolExp{left: yyDollar[1].exp, op: yyDollar[2].cmpOp, right: yyDollar[3].exp} } - case 153: + case 154: yyDollar = yyS[yypt-3 : yypt+1] { yyVAL.binExp = &CmpBoolExp{left: yyDollar[1].exp, op: EQ, right: &NullValue{t: AnyType}} } - case 154: + case 155: yyDollar = yyS[yypt-4 : yypt+1] { yyVAL.binExp = &CmpBoolExp{left: yyDollar[1].exp, op: NE, right: &NullValue{t: AnyType}} diff --git a/embedded/sql/stmt.go b/embedded/sql/stmt.go index f09371d1bd..01a7f08b5c 100644 --- a/embedded/sql/stmt.go +++ b/embedded/sql/stmt.go @@ -484,6 +484,38 @@ func (stmt *AddColumnStmt) execAt(ctx context.Context, tx *SQLTx, params map[str return tx, nil } +type RenameTableStmt struct { + oldName string + newName string +} + +func (stmt *RenameTableStmt) inferParameters(ctx context.Context, tx *SQLTx, params map[string]SQLValueType) error { + return nil +} + +func (stmt *RenameTableStmt) execAt(ctx context.Context, tx *SQLTx, params map[string]interface{}) (*SQLTx, error) { + table, err := tx.catalog.renameTable(stmt.oldName, stmt.newName) + if err != nil { + return nil, err + } + + // update table name + mappedKey := MapKey( + tx.sqlPrefix(), + catalogTablePrefix, + EncodeID(DatabaseID), + EncodeID(table.id), + ) + err = tx.set(mappedKey, nil, []byte(stmt.newName)) + if err != nil { + return nil, err + } + + tx.mutatedCatalog = true + + return tx, nil +} + type RenameColumnStmt struct { table string oldName string