Skip to content

Commit

Permalink
Merge pull request #1602 from taozhi8833998/fix-missing-parentheses
Browse files Browse the repository at this point in the history
fix: datatype length missing parentheses in all db
  • Loading branch information
taozhi8833998 authored Sep 29, 2023
2 parents 2e2935f + b0e745f commit 077dadc
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 10 deletions.
6 changes: 5 additions & 1 deletion pegjs/bigquery.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2975,7 +2975,11 @@ data_type
/ bool_byte_geography_type

character_string_type
= t:KW_STRING (__ LPAREN __ l:[0-9]+ __ RPAREN)* { return { dataType: t }; }
= t:KW_STRING s:(__ LPAREN __ l:[0-9]+ __ RPAREN)* {
const result = { dataType: t }
if (!s || s.length === 0) return result
return { ...result, length: parseInt(s[3].join(''), 10), parentheses: true };
}

numeric_type
= t:(KW_NUMERIC / KW_INT_64 / KW_FLOAT_64 / KW_INTEGER) { return { dataType: t }; }
Expand Down
2 changes: 1 addition & 1 deletion pegjs/db2.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2571,7 +2571,7 @@ data_type

character_string_type
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ t:KW_CHAR { return { dataType: t }; }
/ t:KW_VARCHAR { return { dataType: t }; }
Expand Down
2 changes: 1 addition & 1 deletion pegjs/flinksql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3696,7 +3696,7 @@ boolean_type
character_string_type
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
// => data_type
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ t:KW_CHAR { /* => data_type */ return { dataType: t }; }
/ t:KW_VARCHAR { /* => data_type */ return { dataType: t }; }
Expand Down
2 changes: 1 addition & 1 deletion pegjs/hive.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2562,7 +2562,7 @@ data_type

character_string_type
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ t:(KW_CHAR / KW_VARCHAR / KW_STRING) { return { dataType: t }; }

Expand Down
2 changes: 1 addition & 1 deletion pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3578,7 +3578,7 @@ binary_type

character_string_type
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ t:KW_CHAR { return { dataType: t }; }
/ t:KW_VARCHAR { return { dataType: t }; }
Expand Down
2 changes: 1 addition & 1 deletion pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3881,7 +3881,7 @@ binary_type

character_string_type
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ t:KW_CHAR { return { dataType: t }; }
/ t:KW_VARCHAR { return { dataType: t }; }
Expand Down
2 changes: 1 addition & 1 deletion pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -5196,7 +5196,7 @@ character_varying
character_string_type
= t:(KW_CHAR / KW_VARCHAR / character_varying) __ LPAREN __ l:[0-9]+ __ RPAREN {
// => data_type
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ t:(KW_CHAR / character_varying / KW_VARCHAR) { /* => data_type */ return { dataType: t }; }

Expand Down
2 changes: 1 addition & 1 deletion pegjs/snowflake.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -4596,7 +4596,7 @@ binary_type
character_string_type
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
// => data_type
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ t:(KW_CHAR / KW_CHARACTER) { /* => data_type */ return { dataType: t }; }
/ t:KW_VARCHAR { /* => data_type */ return { dataType: t }; }
Expand Down
2 changes: 1 addition & 1 deletion pegjs/sqlite.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -2756,7 +2756,7 @@ boolean_type

character_string_type
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ t:KW_CHAR { return { dataType: t }; }
/ t:KW_VARCHAR { return { dataType: t }; }
Expand Down
2 changes: 1 addition & 1 deletion pegjs/transactsql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -3134,7 +3134,7 @@ data_type

character_string_type
= lb:LBRAKE? __ t:(KW_CHAR / KW_VARCHAR / KW_NCHAR / KW_NVARCHAR) __ rb:RBRAKE? !{ return (lb && !rb) || (!lb && rb) } __ LPAREN __ l:[0-9]+ __ RPAREN {
return { dataType: t, length: parseInt(l.join(''), 10) };
return { dataType: t, length: parseInt(l.join(''), 10), parentheses: true };
}
/ lb:LBRAKE? __ t:(KW_CHAR / KW_VARCHAR) __ rb:RBRAKE? !{ return (lb && !rb) || (!lb && rb) } {
return { dataType: t };
Expand Down
7 changes: 7 additions & 0 deletions test/postgres.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,13 @@ describe('Postgres', () => {
'SELECT "c"::REGTYPE FROM "pg_attribute"'
]
},
{
title: 'cast varchar with length',
sql: [
'SELECT name::VARCHAR(200) FROM raw_hosts',
'SELECT "name"::VARCHAR(200) FROM "raw_hosts"'
]
},
{
title: 'chinese oridinary identifier',
sql: [
Expand Down

0 comments on commit 077dadc

Please sign in to comment.