Skip to content

Commit d49f9f4

Browse files
Merge pull request #2284 from taozhi8833998/feat-trim-expr
feat: support trim expr in all db
2 parents 0c9cda4 + 05e3546 commit d49f9f4

10 files changed

+26
-9
lines changed

pegjs/athena.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2141,7 +2141,7 @@ trim_position
21412141
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
21422142

21432143
trim_rem
2144-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
2144+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
21452145
let value = []
21462146
if (p) value.push({type: 'origin', value: p })
21472147
if (rm) value.push(rm)

pegjs/flinksql.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2968,7 +2968,7 @@ trim_position
29682968
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
29692969

29702970
trim_rem
2971-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
2971+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
29722972
// => expr_list
29732973
let value = []
29742974
if (p) value.push({type: 'origin', value: p })

pegjs/mariadb.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3246,7 +3246,7 @@ trim_position
32463246
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
32473247

32483248
trim_rem
3249-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
3249+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
32503250
let value = []
32513251
if (p) value.push({type: 'origin', value: p })
32523252
if (rm) value.push(rm)

pegjs/mysql.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3535,7 +3535,7 @@ trim_position
35353535
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
35363536

35373537
trim_rem
3538-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
3538+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
35393539
let value = []
35403540
if (p) value.push({type: 'origin', value: p })
35413541
if (rm) value.push(rm)

pegjs/noql.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4312,7 +4312,7 @@ trim_position
43124312
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
43134313

43144314
trim_rem
4315-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
4315+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
43164316
// => expr_list
43174317
let value = []
43184318
if (p) value.push({type: 'origin', value: p })

pegjs/postgresql.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4897,7 +4897,7 @@ trim_position
48974897
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
48984898

48994899
trim_rem
4900-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
4900+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
49014901
// => expr_list
49024902
let value = []
49034903
if (p) value.push({type: 'origin', value: p })

pegjs/redshift.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4371,7 +4371,7 @@ trim_position
43714371
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
43724372

43734373
trim_rem
4374-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
4374+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
43754375
// => expr_list
43764376
let value = []
43774377
if (p) value.push({type: 'origin', value: p })

pegjs/snowflake.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3806,7 +3806,7 @@ trim_position
38063806
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
38073807

38083808
trim_rem
3809-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
3809+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
38103810
// => expr_list
38113811
let value = []
38123812
if (p) value.push({type: 'origin', value: p })

pegjs/trino.pegjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3785,7 +3785,7 @@ trim_position
37853785
= 'BOTH'i / 'LEADING'i / 'TRAILING'i
37863786

37873787
trim_rem
3788-
= p:trim_position? __ rm:literal_string? __ k:KW_FROM {
3788+
= p:trim_position? __ rm:expr? __ k:KW_FROM {
37893789
// => expr_list
37903790
let value = []
37913791
if (p) value.push({type: 'origin', value: p })

test/mysql-mariadb.spec.js

+17
Original file line numberDiff line numberDiff line change
@@ -1182,6 +1182,23 @@ describe('mysql', () => {
11821182
'SELECT `users`.`id` FROM `users` LEFT JOIN `orders` ON `users`.`id` COLLATE utf8mb4_general_ci = `orders`.`user_id`',
11831183
]
11841184
},
1185+
{
1186+
title: 'trim expr from',
1187+
sql: [
1188+
`create table \`table1\` (
1189+
\`id\` int primary key not null,
1190+
\`data\` varchar(255) not null,
1191+
\`removed_id\` varchar(55) GENERATED ALWAYS AS (
1192+
trim(
1193+
trailing concat('.',substring_index(\`data\`,'.',-(3)))
1194+
from
1195+
trim(leading concat(substring_index(\`data\`,'.',3),'.') from \`data\`)
1196+
)
1197+
) STORED
1198+
);`,
1199+
"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)"
1200+
]
1201+
},
11851202
]
11861203
SQL_LIST.forEach(sqlInfo => {
11871204
const { title, sql } = sqlInfo

0 commit comments

Comments
 (0)