Bug Report
- What did you do?
Looking at the ddl tests in the testDDLSuite, I was under the impression from TestDDLOnUpdateRestore that parsing sql statements with "ON UPDATE" were supported, however, in attempting to parse the following statement I encountered an error.
Code snippet:
p := parser.New()
testSQL := "create table test(id int key, FOREIGN KEY (id) REFERENCES test2(id) ON UPDATE CASCADE);"
if _, _, err := p.Parse(testSQL, "", ""); err != nil {
logger.Error("failed to parse", zap.Error(err))
}
- What did you expect to see?
I expected this statement to be able to be parsed without an issue.
- What did you see instead?
I encountered the error "error":"line 1 column 77 near \"UPDATE CASCADE);\"
Looking closer at the current tests in TestDDLOnUpdateRestore
func (ts *testDDLSuite) TestDDLOnUpdateRestore(c *C) {
testCases := []NodeRestoreTestCase{
{"ON UPDATE RESTRICT", "ON UPDATE RESTRICT"},
{"on update CASCADE", "ON UPDATE CASCADE"},
{"on update SET NULL", "ON UPDATE SET NULL"},
{"on update no action", "ON UPDATE NO ACTION"},
}
extractNodeFunc := func(node Node) Node {
return node.(*CreateTableStmt).Constraints[1].Refer.OnUpdate
}
RunNodeRestoreTest(c, testCases, "CREATE TABLE child ( id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) ON DELETE CASCADE %s )", extractNodeFunc)
}
All ON UPDATE test cases are inserted after an ON DELETE CASCADE clause. When I removed, the ON DELETE and instead used
RunNodeRestoreTest(c, testCases, "CREATE TABLE child ( id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) %s )", extractNodeFunc)
The tests for TestDDLOnUpdateRestore start to fail
----------------------------------------------------------------------
FAIL: ddl_test.go:91: testDDLSuite.TestDDLOnUpdateRestore
ddl_test.go:101:
RunNodeRestoreTest(c, testCases, "CREATE TABLE child ( id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) %s )", extractNodeFunc)
util_test.go:113:
c.Assert(err, IsNil, comment)
... value *errors.withStack = line 1 column 126 near "UPDATE RESTRICT )" ("line 1 column 126 near \"UPDATE RESTRICT )\" ")
... source ast_test.NodeRestoreTestCase{sourceSQL:"ON UPDATE RESTRICT", expectSQL:"ON UPDATE RESTRICT"}
Are DDL statements like create table test(id int key, FOREIGN KEY (id) REFERENCES test2(id) ON UPDATE CASCADE); not supported?
- What version of TiDB SQL Parser are you using?
My go.mod file looks like this:
github.com/pingcap/parser v0.0.0-20190312024907-3f6280b08c8b
github.com/pingcap/tidb v0.0.0-20181120082053-821af9e9f65b9901bcac1661f28c41985697b511
Bug Report
Looking at the ddl tests in the
testDDLSuite, I was under the impression fromTestDDLOnUpdateRestorethat parsing sql statements with "ON UPDATE" were supported, however, in attempting to parse the following statement I encountered an error.Code snippet:
I expected this statement to be able to be parsed without an issue.
I encountered the error
"error":"line 1 column 77 near \"UPDATE CASCADE);\"Looking closer at the current tests in
TestDDLOnUpdateRestoreAll
ON UPDATEtest cases are inserted after anON DELETE CASCADEclause. When I removed, theON DELETEand instead usedRunNodeRestoreTest(c, testCases, "CREATE TABLE child ( id INT, parent_id INT, INDEX par_ind (parent_id), FOREIGN KEY (parent_id) REFERENCES parent(id) %s )", extractNodeFunc)The tests for
TestDDLOnUpdateRestorestart to failAre DDL statements like
create table test(id int key, FOREIGN KEY (id) REFERENCES test2(id) ON UPDATE CASCADE);not supported?My go.mod file looks like this: