sqlparser icon indicating copy to clipboard operation
sqlparser copied to clipboard

unexpected error parsing DDL using FOREIGN KEY

Open thurt opened this issue 8 years ago • 2 comments

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?

thurt avatar Dec 08 '17 19:12 thurt

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

bramp avatar Dec 09 '17 23:12 bramp