Skip to content

fix: add partition in mysql #2396

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ alter_table_add_partition
name: n,
value: {
type: 'less than',
value: v,
expr: v,
parentheses: true,
}
}
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -1261,7 +1261,7 @@ alter_table_add_partition
name: n,
value: {
type: 'less than',
value: v,
expr: v,
parentheses: true,
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/alter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { dataTypeToSQL, hasVal, toUpper, identifierToSql, literalToSQL } from '.
function alterExprPartition(action, expr) {
switch (action) {
case 'add':
const { name, value } = expr
return ['PARTITION', literalToSQL(name), toUpper(value.type), `(${literalToSQL(value.value)})`];
const sql = expr.map(({ name, value }) => ['PARTITION', literalToSQL(name), 'VALUES', toUpper(value.type), `(${literalToSQL(value.expr)})`].join(' ')).join(', ')
return `(${sql})`
default:
return columnsToSQL(expr)
return columnsToSQL(expr)
}
}
function alterExprToSQL(expr) {
Expand Down
2 changes: 1 addition & 1 deletion test/mysql-mariadb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ describe('mysql', () => {
title: 'alter table add partition',
sql: [
'ALTER TABLE test_table ADD PARTITION (PARTITION p202503 VALUES LESS THAN (20250301), PARTITION p202504 VALUES LESS THAN (20250401));',
'ALTER TABLE `test_table` ADD PARTITION (`PARTITION` `p202503` VALUES LESS THAN (20250301), `PARTITION` `p202504` VALUES LESS THAN (20250401))'
'ALTER TABLE `test_table` ADD PARTITION (PARTITION p202503 VALUES LESS THAN (20250301), PARTITION p202504 VALUES LESS THAN (20250401))'
]
},
]
Expand Down