Repository navigation
Description
Is there an existing issue for the same bug?
- I have checked the existing issues (including the escaping-behavior
reports like [Bug]: CSV OUTFILE leaves delimiters unescaped in unquoted values, breaking round-trip #30702, which this complements from the syntax side).
Branch Name
main
Commit ID
a648b13 (verified live on the published image matrixorigin/matrixone:main-a648b13e53)
Summary
SELECT ... INTO OUTFILE does not accept the FIELDS ESCAPED BY or
LINES STARTING BY clauses. Both are part of MySQL 8's SELECT ... INTO OUTFILE grammar (full FIELDS/LINES handling, same as LOAD DATA), so
dump/export scripts written for MySQL fail to parse on MatrixOne. MO's
LOAD DATA side does accept both clauses end to end (verified below),
which makes the asymmetry concrete and blocks the natural round-trip: one
can re-import with an explicit escape character / line prefix, but cannot
export with the matching configuration.
This syntax gap is also the missing knob for the escaping-behavior work
tracked in #30702: users currently have no way to disable escaping
(ESCAPED BY '') or choose a non-backslash escape character for exports,
whichever way the writer side lands.
Steps to Reproduce
-- both are valid MySQL 8 OUTFILE statements; both fail to parse on MO
select 1 into outfile '/tmp/out1.csv'
FIELDS TERMINATED BY ',' ENCLOSED BY '' ESCAPED BY '\\';
-- ERROR 1064 (42000): ... syntax error at line 1 column 110 near " ESCAPED BY '\\'";
select 1 into outfile '/tmp/out2.csv'
LINES STARTING BY '>>' TERMINATED BY '\n';
-- ERROR 1064 (42000): ... syntax error at line 1 column 77 near " STARTING BY '>>' TERMINATED BY '\n'";On the same instance the LOAD side accepts both, end to end:
-- /tmp/startby.csv contains: >>alpha,beta\n>>gamma,delta\n
create table sb(a varchar(32), b varchar(32));
load data infile '/tmp/startby.csv' into table sb
FIELDS TERMINATED BY ',' ENCLOSED BY '' ESCAPED BY '\\'
LINES STARTING BY '>>' TERMINATED BY '\n' (a, b);
select * from sb order by a;
-- -> alpha/beta and gamma/delta loaded correctly (both clauses honored)Where the grammar stops
pkg/sql/parsers/dialect/mysql/mysql_sql.y, the OUTFILE fields/lines
productions (rules around case 975-980 in the generated parser): FIELDS
only handles TERMINATED BY / ENCLOSED BY [OPTIONALLY], and LINES only
TERMINATED BY. The tree.Fields/tree.Lines structures and
tree.ExportParam already carry EscapedBy/StartingBy — only the OUTFILE
grammar block is missing them (the LOAD DATA field rules already produce
tree.EscapedBy).
Actual Behavior
Parse error; the clauses are absent only from the OUTFILE forms.
Expected Behavior
Support the MySQL clauses in SELECT ... INTO OUTFILE:
FIELDS [TERMINATED BY str] [OPTIONALLY] [ENCLOSED BY str] [ESCAPED BY str],
includingESCAPED BY ''(escaping disabled — writer must then emit values
verbatim), with validation consistent with MySQL (single byte; only the
empty string is exempt);LINES [STARTING BY str] [TERMINATED BY str];- writer semantics honored during export (escape-character selection,
line-prefix writing), so a dump made with these options reloads via the
matching LOAD DATA options.
Acceptance criteria
Both statements above parse and their semantics are honored byte-exactly on
the exported file, and a file exported with unusual terminators (e.g.
LINES STARTING BY '>>', custom escape byte) round-trips back through the
matching LOAD DATA clause set.
Other Environment Information
- Image
matrixorigin/matrixone:main-a648b13e53, docker quickstart single process. - Grammar analysis and live parse checks performed by @matrix-meow.
Activity
daviszhen commentedon Oct 21, 2026
X-ref: #30702 (writer-side escaping fix in flight — this issue is the syntax-side enabler: without FIELDS ESCAPED BY, exporters cannot pick or disable the escape byte at all).
XuPeng-SH commentedon Oct 22, 2026
This report is now tracked together with #30710. The canonical issue retains explicit acceptance cases for the behavior described here. This is an administrative duplicate/consolidation closure only; the underlying defect is not claimed fixed. The original description and discussion remain available on this issue.
fix(outfile): accept FIELDS ESCAPED BY/LINES STARTING BY and reject n…