Repository navigation
Don't treat [ as an identifier quote on PostgreSQL or MySQL - #11
Conversation
In PostgreSQL, brackets are array syntax. A ] inside a string in an ARRAY literal (ARRAY['x]']) ended the bracket "quote" early, and the next ' opened a string that ran to the end of the file, so the rest of the migration went to the server as one statement. Postgres.jl then rejected it with "cannot insert multiple commands into a prepared statement". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MySQL has no bracket arrays; it simply never quotes identifiers with brackets. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
[review generated via AI]
Verdict: PASS. I pushed one comment-only commit (5557660).
Checked
- With
main'ssrc, the new test fails 2 of 2: the whole file reaches the driver as one statement. On the head it passes. - The root cause is right.
[started a "quoted identifier" that closed at the]inside'x]', so the next'opened a string that never closed. - SQLite and ODBC are unchanged.
bracketquotes = !mysqlcomments && !usesdollarmarkers(conn)istruefor SQLite, ODBC and any unrecognized driver, and the public one-argumentsplitsqlstatements(sql)still bracket-quotes. A real SQLite run throughrunmigrationson the head withCREATE TABLE [we;ird] ...; INSERT INTO [we;ird] ...; CREATE TABLE [it's] ...; INSERT INTO [it's] ...applies cleanly and reads back 1 and 2. That shows both;and'inside brackets are still protected. - Dropping bracket quoting on MySQL is right. MySQL quotes identifiers with backticks (or double quotes under
ANSI_QUOTES) and has no bracket syntax outside string literals such as JSON paths, so[never had a quoting meaning there. - Real PostgreSQL 14 through Postgres.jl on the head: a migration with
ARRAY['x]', 'y'],DEFAULT ARRAY['[0-9]+;', 'a]b'](a;and a]inside array strings), an insert, and an array slice(ARRAY[1,2,3])[2:3]applies, and the stored value reads back as{[0-9]+;,a]b}. - There are no other internal callers of the splitter. The README and
runmigrationsdocstring say "quoted identifiers" generically, which stays accurate.
Pushed: the new code comment said "PostgreSQL and MySQL use brackets for array subscripts and literals". MySQL has no arrays; the reason is that it never quotes with brackets. I reworded that comment only. The suite still passes (284/284).
Ran: full Pkg.test() on Julia 1.12, on the head and with main's src. CI passes on 1.6 (the floor), 1 and nightly. The only failing check is codecov/project, the known baseline mismatch.
Not covered, not a blocker: an ODBC connection to PostgreSQL or Snowflake (both use [...] for arrays) still bracket-quotes, because the driver is detected by package, not backend. splitstatements=false is the workaround there.
[comment generated via AI]
What went wrong: on PostgreSQL, a valid migration like this one failed:
Root cause: the statement splitter treats
[...]as a quoted identifier, as in SQLite and SQL Server. In PostgreSQL, brackets are array syntax. The]inside'x]'closed the bracket "quote", the following'opened a string that never closed, and everything after it went to the server as one statement. The same happens with any array literal whose strings contain], such as regex patterns likeARRAY['[0-9]+']. With LibPQ's simple-query path the joined text would still run, but Postgres.jl prepares each statement and rejects it.Fix:
splitsqlstatementsgets abracketquotesflag.runmigrationsturns it off for PostgreSQL connections (LibPQ, Postgres.jl) and MySQL, neither of which quotes identifiers with brackets. SQLite, ODBC and other drivers keep bracket quoting. The one-argumentsplitsqlstatements(sql)is unchanged.Verified:
mainand passes with the fix. The full suite passes on Julia 1.12 (284 tests).main: the error above. With the fix: both tables are created and the history row is recorded.🤖 Generated with Claude Code