Skip to content

Commit

Permalink
feat: support trim expr in all db
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Dec 29, 2024
1 parent 0c9cda4 commit 05e3546
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pegjs/athena.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
let value = []
if (p) value.push({type: 'origin', value: p })
if (rm) value.push(rm)
Expand Down
2 changes: 1 addition & 1 deletion pegjs/flinksql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2968,7 +2968,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
// => expr_list
let value = []
if (p) value.push({type: 'origin', value: p })
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3246,7 +3246,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
let value = []
if (p) value.push({type: 'origin', value: p })
if (rm) value.push(rm)
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3535,7 +3535,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
let value = []
if (p) value.push({type: 'origin', value: p })
if (rm) value.push(rm)
Expand Down
2 changes: 1 addition & 1 deletion pegjs/noql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4312,7 +4312,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
// => expr_list
let value = []
if (p) value.push({type: 'origin', value: p })
Expand Down
2 changes: 1 addition & 1 deletion pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4897,7 +4897,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
// => expr_list
let value = []
if (p) value.push({type: 'origin', value: p })
Expand Down
2 changes: 1 addition & 1 deletion pegjs/redshift.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4371,7 +4371,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
// => expr_list
let value = []
if (p) value.push({type: 'origin', value: p })
Expand Down
2 changes: 1 addition & 1 deletion pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3806,7 +3806,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
// => expr_list
let value = []
if (p) value.push({type: 'origin', value: p })
Expand Down
2 changes: 1 addition & 1 deletion pegjs/trino.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3785,7 +3785,7 @@ trim_position
= 'BOTH'i / 'LEADING'i / 'TRAILING'i

trim_rem
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
= p:trim_position? __ rm:expr? __ k:KW_FROM {
// => expr_list
let value = []
if (p) value.push({type: 'origin', value: p })
Expand Down
17 changes: 17 additions & 0 deletions test/mysql-mariadb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1182,6 +1182,23 @@ describe('mysql', () => {
'SELECT `users`.`id` FROM `users` LEFT JOIN `orders` ON `users`.`id` COLLATE utf8mb4_general_ci = `orders`.`user_id`',
]
},
{
title: 'trim expr from',
sql: [
`create table \`table1\` (
\`id\` int primary key not null,
\`data\` varchar(255) not null,
\`removed_id\` varchar(55) GENERATED ALWAYS AS (
trim(
trailing concat('.',substring_index(\`data\`,'.',-(3)))
from
trim(leading concat(substring_index(\`data\`,'.',3),'.') from \`data\`)
)
) STORED
);`,
"CREATE TABLE `table1` (`id` INT NOT NULL PRIMARY KEY, `data` VARCHAR(255) NOT NULL, `removed_id` VARCHAR(55) GENERATED ALWAYS AS (TRIM(TRAILING concat('.', substring_index(`data`, '.', -(3))) FROM TRIM(LEADING concat(substring_index(`data`, '.', 3), '.') FROM `data`))) STORED)"
]
},
]
SQL_LIST.forEach(sqlInfo => {
const { title, sql } = sqlInfo
Expand Down

0 comments on commit 05e3546

Please sign in to comment.