sqlglot icon indicating copy to clipboard operation
sqlglot copied to clipboard

MySQL: comment inside CREATE TABLE properties is kept on first generation, silently dropped on the second

Open Sun-Wukhan opened this issue 2 weeks ago • 0 comments

Fully reproducible code snippet

import sqlglot

s = "CREATE TABLE t (a INT) ENGINE=InnoDB, /* c */ ROW_FORMAT=DYNAMIC"
g1 = sqlglot.transpile(s, read="mysql", write="mysql")[0]
# 'CREATE TABLE t (a INT) ENGINE=InnoDB /* c */ ROW_FORMAT=DYNAMIC'
g2 = sqlglot.transpile(g1, read="mysql", write="mysql")[0]
# 'CREATE TABLE t (a INT) ENGINE=InnoDB ROW_FORMAT=DYNAMIC'  (comment gone)

The input is taken from sqlglot's own MySQL tests.

Expected

A comment that sqlglot preserves and prints on the first generation should survive repeated round trips, or be dropped consistently on the first pass. Silently losing user content on the second pass is a fidelity defect even though the SQL semantics are unchanged.

Actual

The first generation keeps /* c */ (and drops the comma before it). Re-parsing the generated text attaches the comment at a point the generator no longer emits, so the second generation drops it entirely. It converges after the loss (g3 == g2).

Checked against main at commit b294f7f.

Official Documentation

MySQL CREATE TABLE (table options): https://dev.mysql.com/doc/refman/8.0/en/create-table.html

Found by property-based testing (a round-trip fixed-point property over sqlglot's own test corpus).

Sun-Wukhan avatar Nov 14 '26 21:11 Sun-Wukhan