We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
After creating a table in mysql, and getting the create sql string with SHOW CREATE TABLE, sqlglot is unable to parse the returned string.
SHOW CREATE TABLE
I expect that sqlglot to correctly parse valid MySQL strings.
CREATE TABLE foo ( id CHAR(36) DEFAULT (UUID()) UNIQUE, created_at TIMESTAMP, PRIMARY KEY (id) )
SHOW CREATE TABLE foo > CREATE TABLE `foo` ( `id` char(36) NOT NULL DEFAULT (uuid()), `created_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
sql = """CREATE TABLE `foo` ( `id` char(36) NOT NULL DEFAULT (uuid()), `created_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci""" sqlglot.parse_one(sql, "mysql") >>> ParseError: Expecting ). Line 6, Col: 12. T NULL DEFAULT (uuid()), `created_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
If you remove the UNIQUE KEY line the string will parse.
UNIQUE KEY
sql = """CREATE TABLE `foo` ( `id` char(36) NOT NULL DEFAULT (uuid()), `created_at` timestamp NULL DEFAULT NULL, PRIMARY KEY (`id`), ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci""" sqlglot.parse_one(sql, "mysql") >>> (CREATE this: (SCHEMA this: (TABLE this: (IDENTIFIER this: foo, quoted: True)), expressions: (COLUMNDEF this: (IDENTIFIER this: id, quoted: True), kind: (DATATYPE this: Type.CHAR, expressions: (DATATYPESIZE this: (LITERAL this: 36, is_string: False)), nested: False, prefix: False), constraints: (COLUMNCONSTRAINT kind: (NOTNULLCOLUMNCONSTRAINT )), (COLUMNCONSTRAINT kind: (DEFAULTCOLUMNCONSTRAINT this: (PAREN this: (ANONYMOUS this: uuid))))), (COLUMNDEF this: (IDENTIFIER this: created_at, quoted: True), kind: (DATATYPE this: Type.TIMESTAMP), constraints: (COLUMNCONSTRAINT kind: (NOTNULLCOLUMNCONSTRAINT allow_null: True)), (COLUMNCONSTRAINT kind: (DEFAULTCOLUMNCONSTRAINT this: (NULL )))), (PRIMARYKEY expressions: (IDENTIFIER this: id, quoted: True))), kind: TABLE, properties: (PROPERTIES expressions: (ENGINEPROPERTY this: (IDENTIFIER this: InnoDB, quoted: False)), (CHARACTERSETPROPERTY this: (VAR this: utf8mb4), default: True), (COLLATEPROPERTY this: (IDENTIFIER this: utf8mb4_0900_ai_ci, quoted: False))))
How can I parse sql string with a UNIQUE key?
UNIQUE
Thank you in advance for any help.
The text was updated successfully, but these errors were encountered:
Successfully merging a pull request may close this issue.
After creating a table in mysql, and getting the create sql string with
SHOW CREATE TABLE
, sqlglot is unable to parse the returned string.I expect that sqlglot to correctly parse valid MySQL strings.
If you remove the
UNIQUE KEY
line the string will parse.How can I parse sql string with a
UNIQUE
key?Thank you in advance for any help.
The text was updated successfully, but these errors were encountered: