diff --git a/pegjs/mysql.pegjs b/pegjs/mysql.pegjs index ac6374a5..13d4d938 100644 --- a/pegjs/mysql.pegjs +++ b/pegjs/mysql.pegjs @@ -1228,12 +1228,12 @@ alter_table_stmt }; } alter_column_suffix - = k:('after'i / 'first'i) __ i:column_ref { - return { - keyword: k, - expr: i + = k:"first"i { + return { keyword: k }; + } + / k:"after"i __ i:column_ref { + return { keyword: k, expr: i }; } - } alter_action_list = head:alter_action tail:(__ COMMA __ alter_action)* { return createList(head, tail); diff --git a/pegjs/sqlite.pegjs b/pegjs/sqlite.pegjs index 5cbdfe65..2b35e999 100644 --- a/pegjs/sqlite.pegjs +++ b/pegjs/sqlite.pegjs @@ -781,12 +781,12 @@ alter_table_stmt } alter_column_suffix - = k:('after'i / 'first'i) __ i:column_ref { - return { - keyword: k, - expr: i + = k:"first"i { + return { keyword: k }; + } + / k:"after"i __ i:column_ref { + return { keyword: k, expr: i }; } - } alter_action_list = head:alter_action tail:(__ COMMA __ alter_action)* { diff --git a/src/alter.js b/src/alter.js index 4dc0688c..530c3392 100644 --- a/src/alter.js +++ b/src/alter.js @@ -64,8 +64,10 @@ function alterExprToSQL(expr) { toUpper(prefix), name && name.trim(), dataType.filter(hasVal).join(' '), - suffix && `${toUpper(suffix.keyword)}${suffix.expr ? ` ${columnRefToSQL(suffix.expr)}` : ''}`, ] + if (suffix) { + alterArray.push(toUpper(suffix.keyword), suffix.expr && columnRefToSQL(suffix.expr)) + } return alterArray.filter(hasVal).join(' ') }