Skip to content

Commit 8a132a3

Browse files
committed
feat: support with cte values in all db
1 parent c407716 commit 8a132a3

17 files changed

Lines changed: 111 additions & 82 deletions

pegjs/athena.pegjs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,13 +1223,13 @@ table_base
12231223
}
12241224
/ stmt:value_clause __ alias:value_alias_clause? {
12251225
return {
1226-
expr: { type: 'values', values: stmt },
1226+
expr: stmt,
12271227
as: alias
12281228
};
12291229
}
12301230
/ LPAREN __ stmt:value_clause __ RPAREN __ alias:value_alias_clause? {
12311231
return {
1232-
expr: { type: 'values', values: stmt, parentheses: true },
1232+
expr: { ...stmt, parentheses: true },
12331233
as: alias
12341234
};
12351235
}
@@ -1531,8 +1531,8 @@ replace_insert_stmt
15311531
}
15321532
if (c) {
15331533
let table = t && t.table || null
1534-
if(Array.isArray(v)) {
1535-
v.forEach((row, idx) => {
1534+
if(Array.isArray(v.values)) {
1535+
v.values.forEach((row, idx) => {
15361536
if(row.value.length != c.length) {
15371537
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
15381538
}
@@ -1587,7 +1587,7 @@ replace_insert
15871587
/ KW_REPLACE { return 'replace'; }
15881588

15891589
value_clause
1590-
= KW_VALUES __ l:value_list { return l; }
1590+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
15911591

15921592
value_list
15931593
= head:value_item tail:(__ COMMA __ value_item)* {

pegjs/bigquery.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ replace_insert_stmt
359359
}
360360
if (c) {
361361
let table = t && t.table || null
362-
if(Array.isArray(v)) {
363-
v.forEach((row, idx) => {
362+
if(Array.isArray(v.values)) {
363+
v.values.forEach((row, idx) => {
364364
if(row.value.length != c.length) {
365365
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
366366
}
@@ -856,7 +856,7 @@ value_item
856856
}
857857

858858
value_clause
859-
= KW_VALUES __ l:value_list { return l; }
859+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
860860

861861
drop_index_opt
862862
= head:(ALTER_ALGORITHM / ALTER_LOCK) tail:(__ (ALTER_ALGORITHM / ALTER_LOCK))* {

pegjs/db2.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,8 +1486,8 @@ replace_insert_stmt
14861486
}
14871487
if (c) {
14881488
let table = t && t.table || null
1489-
if(Array.isArray(v)) {
1490-
v.forEach((row, idx) => {
1489+
if(Array.isArray(v.values)) {
1490+
v.values.forEach((row, idx) => {
14911491
if(row.value.length != c.length) {
14921492
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
14931493
}
@@ -1578,7 +1578,7 @@ replace_insert
15781578
/ KW_REPLACE { return 'replace'; }
15791579

15801580
value_clause
1581-
= KW_VALUES __ l:value_list { return l; }
1581+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
15821582

15831583
value_list
15841584
= head:value_item tail:(__ COMMA __ value_item)* {

pegjs/flinksql.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,8 +2234,8 @@ replace_insert_stmt
22342234
}
22352235
if (c) {
22362236
let table = t && t.table || null
2237-
if(Array.isArray(v)) {
2238-
v.forEach((row, idx) => {
2237+
if(Array.isArray(v.values)) {
2238+
v.values.forEach((row, idx) => {
22392239
if(row.value.length != c.length) {
22402240
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
22412241
}
@@ -2292,7 +2292,7 @@ replace_insert
22922292
/ KW_REPLACE { /* => 'replace' */return 'replace'; }
22932293

22942294
value_clause
2295-
= KW_VALUES __ l:value_list { /* => value_list */ return l; }
2295+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
22962296

22972297
value_list
22982298
= head:value_item tail:(__ COMMA __ value_item)* {

pegjs/hive.pegjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,8 +1472,8 @@ replace_insert_stmt
14721472
}
14731473
if (c) {
14741474
let table = t && t.table || null
1475-
if(Array.isArray(v)) {
1476-
v.forEach((row, idx) => {
1475+
if(Array.isArray(v.values)) {
1476+
v.values.forEach((row, idx) => {
14771477
if(row.value.length != c.length) {
14781478
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
14791479
}
@@ -1528,7 +1528,7 @@ replace_insert
15281528
/ KW_REPLACE { return 'replace'; }
15291529

15301530
value_clause
1531-
= KW_VALUES __ l:value_list { return l; }
1531+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
15321532

15331533
value_list
15341534
= head:value_item tail:(__ COMMA __ value_item)* {

pegjs/mariadb.pegjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,7 +2061,7 @@ with_clause
20612061
}
20622062

20632063
cte_definition
2064-
= name:(literal_string / ident_name / table_name) __ columns:cte_column_definition? __ KW_AS __ LPAREN __ stmt:set_op_stmt __ RPAREN {
2064+
= name:(literal_string / ident_name / table_name) __ columns:cte_column_definition? __ KW_AS __ LPAREN __ stmt:(value_clause / set_op_stmt) __ RPAREN {
20652065
if (typeof name === 'string') name = { type: 'default', value: name }
20662066
if (name.table) name = { type: 'default', value: name.table }
20672067
return { name, stmt, columns };
@@ -2411,12 +2411,11 @@ table_base
24112411
}
24122412
/ stmt:value_clause __ alias:alias_clause? {
24132413
return {
2414-
expr: { type: 'values', values: stmt, prefix: 'row' },
2414+
expr: stmt,
24152415
as: alias
24162416
};
24172417
}
24182418
/ l:('LATERAL'i)? __ LPAREN __ stmt:(set_op_stmt / value_clause) __ RPAREN __ alias:alias_clause? {
2419-
if (Array.isArray(stmt)) stmt = { type: 'values', values: stmt, prefix: 'row' }
24202419
stmt.parentheses = true;
24212420
const result = {
24222421
expr: stmt,
@@ -2654,8 +2653,8 @@ replace_insert_stmt
26542653
}
26552654
if (c) {
26562655
let table = t && t.table || null
2657-
if(Array.isArray(v)) {
2658-
v.forEach((row, idx) => {
2656+
if(Array.isArray(v.values)) {
2657+
v.values.forEach((row, idx) => {
26592658
if(row.value.length != c.length) {
26602659
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
26612660
}
@@ -2756,15 +2755,16 @@ replace_insert
27562755
/ KW_REPLACE { return 'replace'; }
27572756

27582757
value_clause
2759-
= KW_VALUES __ l:value_list { return l; }
2758+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
27602759

27612760
value_list
27622761
= head:value_item tail:(__ COMMA __ value_item)* {
27632762
return createList(head, tail);
27642763
}
27652764

27662765
value_item
2767-
= 'ROW'i? __ LPAREN __ l:expr_list __ RPAREN {
2766+
= r:'ROW'i? __ LPAREN __ l:expr_list __ RPAREN {
2767+
l.prefix = r && r.toLowerCase();
27682768
return l;
27692769
}
27702770

pegjs/mysql.pegjs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2914,8 +2914,8 @@ replace_insert_stmt
29142914
}
29152915
if (c) {
29162916
let table = t && t.table || null
2917-
if(Array.isArray(v)) {
2918-
v.forEach((row, idx) => {
2917+
if(Array.isArray(v.values)) {
2918+
v.values.forEach((row, idx) => {
29192919
if(row.value.length != c.length) {
29202920
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
29212921
}
@@ -3011,15 +3011,16 @@ replace_insert
30113011
/ KW_REPLACE { return 'replace'; }
30123012

30133013
value_clause
3014-
= KW_VALUES __ l:value_list { return l; }
3014+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
30153015

30163016
value_list
30173017
= head:value_item tail:(__ COMMA __ value_item)* {
30183018
return createList(head, tail);
30193019
}
30203020

30213021
value_item
3022-
= 'ROW'i? __ LPAREN __ l:expr_list __ RPAREN {
3022+
= r:'ROW'i? __ LPAREN __ l:expr_list __ RPAREN {
3023+
l.prefix = r && r.toLowerCase();
30233024
return l;
30243025
}
30253026

pegjs/noql.pegjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3037,13 +3037,12 @@ table_base
30373037
/ stmt:value_clause __ alias:value_alias_clause? {
30383038
// => { expr: value_clause; as?: alias_clause; }
30393039
return {
3040-
expr: { type: 'values', values: stmt },
3040+
expr: stmt,
30413041
as: alias
30423042
};
30433043
}
30443044
/ l:('LATERAL'i)? __ LPAREN __ stmt:(union_stmt / value_clause) __ RPAREN __ alias:value_alias_clause? {
30453045
// => { prefix?: string; expr: union_stmt | value_clause; as?: alias_clause; }
3046-
if (Array.isArray(stmt)) stmt = { type: 'values', values: stmt }
30473046
stmt.parentheses = true;
30483047
return {
30493048
prefix: l,
@@ -3508,8 +3507,8 @@ replace_insert_stmt
35083507
}
35093508
if (c) {
35103509
let table = t && t.table || null
3511-
if(Array.isArray(v)) {
3512-
v.forEach((row, idx) => {
3510+
if(Array.isArray(v.values)) {
3511+
v.values.forEach((row, idx) => {
35133512
if(row.value.length != c.length) {
35143513
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
35153514
}
@@ -3567,7 +3566,7 @@ replace_insert
35673566
/ KW_REPLACE { /* => 'replace' */return 'replace'; }
35683567

35693568
value_clause
3570-
= KW_VALUES __ l:value_list { /* => value_list */ return l; }
3569+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
35713570

35723571
value_list
35733572
= head:value_item tail:(__ COMMA __ value_item)* {

pegjs/postgresql.pegjs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3685,13 +3685,12 @@ table_base
36853685
/ stmt:value_clause __ alias:value_alias_clause? {
36863686
// => { expr: value_clause; as?: alias_clause; }
36873687
return {
3688-
expr: { type: 'values', values: stmt },
3688+
expr: stmt,
36893689
as: alias
36903690
};
36913691
}
36923692
/ l:('LATERAL'i)? __ LPAREN __ stmt:(union_stmt / value_clause) __ RPAREN __ alias:value_alias_clause? {
36933693
// => { prefix?: string; expr: union_stmt | value_clause; as?: alias_clause; }
3694-
if (Array.isArray(stmt)) stmt = { type: 'values', values: stmt }
36953694
stmt.parentheses = true;
36963695
return {
36973696
prefix: l,
@@ -4200,8 +4199,8 @@ replace_insert_stmt
42004199
}
42014200
if (c) {
42024201
let table = t && t.table || null
4203-
if(Array.isArray(v)) {
4204-
v.forEach((row, idx) => {
4202+
if(Array.isArray(v.values)) {
4203+
v.values.forEach((row, idx) => {
42054204
if(row.value.length != c.length) {
42064205
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
42074206
}
@@ -4259,7 +4258,10 @@ replace_insert
42594258
/ KW_REPLACE { /* => 'replace' */return 'replace'; }
42604259

42614260
value_clause
4262-
= KW_VALUES __ l:value_list { /* => value_list */ return l; }
4261+
= KW_VALUES __ l:value_list {
4262+
/* => { type: 'values', values: value_list } */
4263+
return { type: 'values', values: l }
4264+
}
42634265

42644266
value_list
42654267
= head:value_item tail:(__ COMMA __ value_item)* {

pegjs/redshift.pegjs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,13 +3063,12 @@ table_base
30633063
/ stmt:value_clause __ alias:value_alias_clause? {
30643064
// => { expr: value_clause; as?: alias_clause; }
30653065
return {
3066-
expr: { type: 'values', values: stmt },
3066+
expr: stmt,
30673067
as: alias
30683068
};
30693069
}
30703070
/ l:('LATERAL'i)? __ LPAREN __ stmt:(union_stmt / value_clause) __ RPAREN __ alias:value_alias_clause? {
30713071
// => { prefix?: string; expr: union_stmt | value_clause; as?: alias_clause; }
3072-
if (Array.isArray(stmt)) stmt = { type: 'values', values: stmt }
30733072
stmt.parentheses = true;
30743073
return {
30753074
prefix: l,
@@ -3536,8 +3535,8 @@ replace_insert_stmt
35363535
}
35373536
if (c) {
35383537
let table = t && t.table || null
3539-
if(Array.isArray(v)) {
3540-
v.forEach((row, idx) => {
3538+
if(Array.isArray(v.values)) {
3539+
v.values.forEach((row, idx) => {
35413540
if(row.value.length != c.length) {
35423541
throw new Error(`Error: column count doesn't match value count at row ${idx+1}`)
35433542
}
@@ -3595,7 +3594,7 @@ replace_insert
35953594
/ KW_REPLACE { /* => 'replace' */return 'replace'; }
35963595

35973596
value_clause
3598-
= KW_VALUES __ l:value_list { /* => value_list */ return l; }
3597+
= KW_VALUES __ l:value_list { return { type: 'values', values: l } }
35993598

36003599
value_list
36013600
= head:value_item tail:(__ COMMA __ value_item)* {

0 commit comments

Comments
 (0)