Skip to content

Commit 087ad1f

Browse files
committed
fix: character varying as data type in pg
1 parent 8cb7119 commit 087ad1f

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

pegjs/postgresql.pegjs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5188,13 +5188,17 @@ boolean_type
51885188
binary_type
51895189
= 'bytea'i { /* => data_type */ return { dataType: 'BYTEA' }; }
51905190

5191+
character_varying
5192+
= KW_CHARACTER __ ('varying'i)? {
5193+
// => string
5194+
return 'CHARACTER VARYING'
5195+
}
51915196
character_string_type
5192-
= t:(KW_CHAR / KW_VARCHAR) __ LPAREN __ l:[0-9]+ __ RPAREN {
5197+
= t:(KW_CHAR / KW_VARCHAR / character_varying) __ LPAREN __ l:[0-9]+ __ RPAREN {
51935198
// => data_type
51945199
return { dataType: t, length: parseInt(l.join(''), 10) };
51955200
}
5196-
/ t:(KW_CHAR / KW_CHARACTER) { /* => data_type */ return { dataType: t }; }
5197-
/ t:KW_VARCHAR { /* => data_type */ return { dataType: t }; }
5201+
/ t:(KW_CHAR / character_varying / KW_VARCHAR) { /* => data_type */ return { dataType: t }; }
51985202

51995203
numeric_type_suffix
52005204
= un: KW_UNSIGNED? __ ze: KW_ZEROFILL? {

test/postgres.spec.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -915,7 +915,7 @@ describe('Postgres', () => {
915915
title: 'support character data type',
916916
sql: [
917917
"SELECT 'x'::character varying;",
918-
`SELECT 'x'::CHARACTER AS "varying"`
918+
`SELECT 'x'::CHARACTER VARYING`
919919
]
920920
},
921921
{
@@ -1346,6 +1346,18 @@ describe('Postgres', () => {
13461346
`SELECT 'Molière' AS "théâtre"`
13471347
]
13481348
},
1349+
{
1350+
title: 'support character varying',
1351+
sql: [
1352+
`CREATE TABLE "public"."authors_table" (
1353+
"author_id" integer NOT NULL,
1354+
"first_name" character varying NOT NULL,
1355+
"last_name" character varying NOT NULL,
1356+
"birth_date" date
1357+
);`,
1358+
'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)'
1359+
]
1360+
},
13491361
]
13501362
function neatlyNestTestedSQL(sqlList){
13511363
sqlList.forEach(sqlInfo => {

0 commit comments

Comments
 (0)