Repository navigation
Conversation
This was referenced Oct 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #406
MySQL's index prefix
a(N)(index only the first N characters of columna) now works inUNIQUE,PRIMARY KEYandINDEXconstraints inCREATE TABLE, and inCREATE [UNIQUE] INDEX.The parse error from the issue was already gone on
develop: the column list ofUNIQUEandCREATE INDEXis a list of expressions, soa(1)parsed as a call to a functiona.CREATE TABLEthen succeeded, and everyINSERTfailed.developCREATE TABLE t7(a TEXT, UNIQUE (a(1)))11INSERT INTO t7 VALUES ('ab')alasql.fn.a is not a function1INSERT INTO t7 VALUES ('ac')alasql.fn.a is not a functionCannot insert record, because it already exists in unique indexCREATE UNIQUE INDEX ux ON t (a(2)), thenINSERTalasql.fn.a is not a functionCREATE TABLE t(a TEXT, PRIMARY KEY (a(2)))CREATE TABLE t(a TEXT, INDEX k (a(1)))1Change
UNIQUE (...)andCREATE INDEXtake expressions, soa(N)parses as a function call. Whenais a column of the table andNa number, it now compiles to the first N characters ofa(String(value).substr(0, N), NULL stays NULL). Any other expression compiles as before, soUNIQUE (UPPER(a))andUNIQUE (MID(a, 1, 2))still work.PRIMARY KEY (...)andINDEX name (...)take a plain column list. The grammar now acceptsa(N)there (IndexColsList), and the primary key uses the prefix. The grammar has the same 282 conflicts asdevelop.Files:
src/60createtable.js(columnPrefixToJS,indexColumnToJS),src/65createindex.js,src/alasqlparser.jison(and the generatedsrc/alasqlparser.js).Tests
test/test406-B.js(test406.jsexists): the query from the issue, several columns with and without a prefix,UNIQUE KEY name (...),CREATE UNIQUE INDEXandCREATE INDEX, NULL and number values, functions inUNIQUE,PRIMARY KEYwith a prefix, andINDEXinCREATE TABLEwith a prefix.Full suite: 2259 pass, 213 skip, 0 fail.
Replaces #2536, which has no code changes.