Skip to content

Commit 8e84176

Browse files
committed
feat: add bit data type in pg
1 parent b29f84c commit 8e84176

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

pegjs/postgresql.pegjs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,6 +5777,7 @@ KW_CIDR = "CIDR"i !ident_start { return 'CIDR'; }
57775777
KW_INET = "INET"i !ident_start { return 'INET'; }
57785778
KW_MACADDR = "MACADDR"i !ident_start { return 'MACADDR'; }
57795779
KW_MACADDR8 = "MACADDR8"i !ident_start { return 'MACADDR8'; }
5780+
KW_BIT = "BIT"i !ident_start { return 'BIT'; }
57805781

57815782
KW_CURRENT_DATE = "CURRENT_DATE"i !ident_start { return 'CURRENT_DATE'; }
57825783
KW_ADD_DATE = "ADDDATE"i !ident_start { return 'ADDDATE'; }
@@ -6143,6 +6144,7 @@ data_type
61436144
/ oid_type
61446145
/ record_type
61456146
/ network_address_type
6147+
/ bit_type
61466148
/ custom_types
61476149

61486150

@@ -6271,6 +6273,21 @@ record_type
62716273
network_address_type
62726274
= t:(KW_INET / KW_CIDR / KW_MACADDR8 / KW_MACADDR) {/* => data_type */ return { dataType: t }}
62736275

6276+
bit_type
6277+
= t:KW_BIT __ v:('varying'i)? __ num:(__ LPAREN __ [0-9]+ __ RPAREN)? {
6278+
/* => data_type */
6279+
let dataType = t
6280+
if (v) {
6281+
dataType += ' VARYING'
6282+
}
6283+
const result = { dataType }
6284+
if (num) {
6285+
result.length = parseInt(num[3].join(''), 10)
6286+
result.parentheses = true
6287+
}
6288+
return result
6289+
}
6290+
62746291
custom_types
62756292
= schema:ident_name __ DOT __ name:ident_without_kw &{ return customTypes.has(`${schema}.${name}`) } {
62766293
// => data_type

test/postgres.spec.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,6 +2332,13 @@ describe('Postgres', () => {
23322332
`CREATE TYPE "public"."Gender" AS ENUM ('MALE', 'FEMALE') ; CREATE TABLE "users" (gender public.Gender)`
23332333
]
23342334
},
2335+
{
2336+
title: 'bit data type',
2337+
sql: [
2338+
'SELECT CAST(1 AS bit)',
2339+
'SELECT CAST(1 AS BIT)',
2340+
]
2341+
},
23352342
]
23362343
neatlyNestTestedSQL(SQL_LIST)
23372344
})

0 commit comments

Comments
 (0)