{"id":"035310c434cb5071","repo":"knex/knex","slug":"parsing-create-index-failed-at-result-input-sli","errorCode":null,"errorMessage":"Parsing CREATE INDEX failed at [${result.input.slice(result.index).map((t) => t.text).join(' ')}] of \"${sql}\"","messagePattern":"Parsing CREATE INDEX failed at \\[(.+?)\\] of \"(.+?)\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/dialects/sqlite3/schema/internal/parser.js","lineNumber":35,"sourceCode":"  const result = createTable({ input: tokenize(sql, TOKENS) });\n\n  if (!result.success) {\n    throw new Error(\n      `Parsing CREATE TABLE failed at [${result.input\n        .slice(result.index)\n        .map((t) => t.text)\n        .join(' ')}] of \"${sql}\"`\n    );\n  }\n\n  return result.ast;\n}\n\nfunction parseCreateIndex(sql) {\n  const result = createIndex({ input: tokenize(sql, TOKENS) });\n\n  if (!result.success) {\n    throw new Error(\n      `Parsing CREATE INDEX failed at [${result.input\n        .slice(result.index)\n        .map((t) => t.text)\n        .join(' ')}] of \"${sql}\"`\n    );\n  }\n\n  return result.ast;\n}\n\nfunction createTable(ctx) {\n  return s(\n    [\n      t({ text: 'CREATE' }, (v) => null),\n      temporary,\n      t({ text: 'TABLE' }, (v) => null),\n      exists,\n      schema,","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/knex/knex/blob/e25d54bcb707714a17f5a5744eba5c4246bb4d1d/lib/dialects/sqlite3/schema/internal/parser.js#L17-L53","documentation":"Same parser infrastructure as CREATE TABLE, but for CREATE INDEX statements. When rebuilding a table knex must re-create its indexes, so it parses each existing CREATE INDEX. If the index DDL uses syntax the parser rejects (partial-index WHERE clauses with unsupported operators, expression indexes with complex expressions, collations, etc.), parsing fails with the unparsed remainder and original SQL.","triggerScenarios":"Any table-rebuild DDL op (dropColumn, setNullable, dropForeign, etc.) on a table that has an index whose CREATE INDEX statement exceeds the parser's coverage. The error surfaces during the index-recreate phase of the rebuild.","commonSituations":"Indexes created via raw SQL with features beyond knex's parser. Expression indexes with functions or operators the parser grammar doesn't handle. Partial indexes with complex predicates.","solutions":["Drop and recreate the problematic index using a parser-compatible CREATE INDEX before running the alter.","Perform the table alter manually with raw SQL so knex's index parser is bypassed.","Simplify the index definition (plain column indexes, simple WHERE clauses) and upgrade knex for broader coverage."],"exampleFix":"// before\nawait knex.schema.alterTable('t', (b) => b.setNullable('c'));\n// index was: CREATE INDEX i ON t (lower(name)) WHERE active = 1;\n// after\nawait knex.raw('DROP INDEX i');\nawait knex.schema.alterTable('t', (b) => b.setNullable('c'));\nawait knex.raw('CREATE INDEX i ON t (lower(name)) WHERE active = 1');","handlingStrategy":"try-catch","validationCode":"const { parseCreateIndex } = require('knex/lib/dialects/sqlite3/schema/internal/parser');\nasync function assertIndexesParsable(knex, table) {\n  const rows = await knex.raw(`select sql from sqlite_master where type='index' and tbl_name=?`, [table]);\n  for (const r of rows) {\n    if (!r.sql) continue;\n    try { parseCreateIndex(r.sql); } catch (e) { throw new Error(`Index DDL not parser-compatible: ${r.sql}`); }\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await knex.schema.alterTable('t', (b) => b.setNullable('c'));\n} catch (e) {\n  if (/Parsing CREATE INDEX failed/i.test(e.message)) {\n    // drop/recreate the offending index manually, or perform raw alter\n  } else throw e;\n}","preventionTips":["Prefer simple index definitions that knex's parser supports.","Pre-flight parse index DDL before alter migrations.","Recreate complex indexes after the alter via raw SQL."],"tags":["sqlite","ddl","parser","indexes"],"analyzedSha":"e25d54bcb707714a17f5a5744eba5c4246bb4d1d","analyzedAt":"2026-08-03T18:35:32.148Z","schemaVersion":2}