Skip to content

Commit

Permalink
fix: character varying as data type in pg
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Sep 16, 2023
1 parent 8cb7119 commit 087ad1f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
10 changes: 7 additions & 3 deletions pegjs/postgresql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -5188,13 +5188,17 @@ boolean_type
binary_type
= 'bytea'i { /* => data_type */ return { dataType: 'BYTEA' }; }

character_varying
= KW_CHARACTER __ ('varying'i)? {
// => string
return 'CHARACTER VARYING'
}
character_string_type
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
= t:(KW_CHAR / KW_VARCHAR / character_varying) __ LPAREN __ l:[0-9]+ __ RPAREN {
// => data_type
return { dataType: t, length: parseInt(l.join(''), 10) };
}
/ t:(KW_CHAR / KW_CHARACTER) { /* => data_type */ return { dataType: t }; }
/ t:KW_VARCHAR { /* => data_type */ return { dataType: t }; }
/ t:(KW_CHAR / character_varying / KW_VARCHAR) { /* => data_type */ return { dataType: t }; }

numeric_type_suffix
= un: KW_UNSIGNED? __ ze: KW_ZEROFILL? {
Expand Down
14 changes: 13 additions & 1 deletion test/postgres.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ describe('Postgres', () => {
title: 'support character data type',
sql: [
"SELECT 'x'::character varying;",
`SELECT 'x'::CHARACTER AS "varying"`
`SELECT 'x'::CHARACTER VARYING`
]
},
{
Expand Down Expand Up @@ -1346,6 +1346,18 @@ describe('Postgres', () => {
`SELECT 'Molière' AS "théâtre"`
]
},
{
title: 'support character varying',
sql: [
`CREATE TABLE "public"."authors_table" (
"author_id" integer NOT NULL,
"first_name" character varying NOT NULL,
"last_name" character varying NOT NULL,
"birth_date" date
);`,
'CREATE TABLE "public"."authors_table" ("author_id" INTEGER NOT NULL, "first_name" CHARACTER VARYING NOT NULL, "last_name" CHARACTER VARYING NOT NULL, "birth_date" DATE)'
]
},
]
function neatlyNestTestedSQL(sqlList){
sqlList.forEach(sqlInfo => {
Expand Down

0 comments on commit 087ad1f

Please sign in to comment.