Skip to content

Commit

Permalink
Merge pull request #1651 from taozhi8833998/feat-insert-ignore-into-m…
Browse files Browse the repository at this point in the history
…ysql

feat: support insert ignore into in mysql
  • Loading branch information
taozhi8833998 authored Nov 8, 2023
2 parents e8b1e66 + 7439fe0 commit 0dfb1c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2177,6 +2177,7 @@ insert_no_columns_stmt

insert_into_set
= ri:replace_insert __
ig:KW_IGNORE? __
it:KW_INTO? __
t:table_name __
p:insert_partition? __
Expand All @@ -2188,6 +2189,7 @@ insert_into_set
columnList.add(`insert::${t.table}::(.*)`);
t.as = null
}
const prefix = [ig, it].filter(v => v).map(v => v[0] && v[0].toLowerCase()).join(' ')
return {
tableList: Array.from(tableList),
columnList: columnListTableAlias(columnList),
Expand All @@ -2196,7 +2198,7 @@ insert_into_set
table: [t],
columns: null,
partition: p,
prefix: it === null ? '' : it[0],
prefix,
set: l,
on_duplicate_update: odp,
}
Expand Down
14 changes: 14 additions & 0 deletions test/mysql-mariadb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,20 @@ describe('mysql', () => {
'SELECT * FROM `2023t`'
]
},
{
title: 'insert ignore into',
sql: [
'INSERT IGNORE INTO tableName SET id=1',
'INSERT IGNORE INTO `tableName` SET `id` = 1'
]
},
{
title: 'expr in column',
sql: [
'SELECT col_1 = 0 AS is_admin FROM sample_table;',
'SELECT `col_1` = 0 AS `is_admin` FROM `sample_table`'
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit 0dfb1c1

Please sign in to comment.