xwb1989 / sqlparser

SQL Parser implemented in Go
Apache License 2.0
1.49k stars 240 forks source link

unexpected error parsing DDL using FOREIGN KEY #26

Open thurt opened 6 years ago

thurt commented 6 years ago

when usingsqlparser.ParseStrictDDL

I receive an error

syntax error at position 290 near 'foreign'

when parsing valid mySQL:

CREATE TABLE `comments` (
  `id` INT UNSIGNED NOT NULL AUTO_INCREMENT,
  `content` TEXT DEFAULT NULL,
  `created` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `last_edited` TIMESTAMP,
  `user_id` VARCHAR(18) NOT NULL,
  `post_id` INT UNSIGNED NOT NULL, 
  PRIMARY KEY (`id`),
  FOREIGN KEY (`user_id`) REFERENCES users(id) ON UPDATE CASCADE ON DELETE CASCADE,
  FOREIGN KEY (`post_id`) REFERENCES posts(id) ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

I expected that foreign key would be parseable?

bramp commented 6 years ago

Parsing of DDL is incomplete, so with Strict there will be issues. I'll keep this open to track improving the parsing.

Agility6 commented 4 days ago

Pls is this problem solved?