Skip to content

Commit 290f3b7

Browse files
committed
Identify PostgreSQL data types, add docs
1 parent 7978ec3 commit 290f3b7

File tree

2 files changed

+78
-21
lines changed

2 files changed

+78
-21
lines changed

docs/datatypeCase.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# datatypeCase (experimental)
2+
3+
Converts datatypes to upper- or lowercase.
4+
5+
This option doesn't yet support all types of data types:
6+
7+
- multi-word data types with non-datatype keywords like `timestamp with time zone` are not fully supported - the `WITH` will be cased as a normal keyword
8+
9+
## Options
10+
11+
- `"preserve"` (default) preserves the original case.
12+
- `"upper"` converts to uppercase.
13+
- `"lower"` converts to lowercase.
14+
15+
### preserve
16+
17+
```sql
18+
CREATE TABLE
19+
users (
20+
id InTeGeR PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
21+
first_name VarChaR(30) NOT NULL,
22+
bio teXT,
23+
is_email_verified BooL NOT NULL DEFAULT FALSE,
24+
created_timestamp timestamPtz NOT NULL DEFAULT NOW()
25+
)
26+
```
27+
28+
### upper
29+
30+
```sql
31+
CREATE TABLE
32+
users (
33+
id INTEGER PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
34+
first_name VARCHAR(30) NOT NULL,
35+
bio TEXT,
36+
is_email_verified BOOL NOT NULL DEFAULT FALSE,
37+
created_timestamp TIMESTAMPTZ NOT NULL DEFAULT NOW()
38+
)
39+
```
40+
41+
### lower
42+
43+
```sql
44+
CREATE TABLE
45+
users (
46+
id integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
47+
first_name varchar(30) NOT NULL,
48+
bio text,
49+
is_email_verified bool NOT NULL DEFAULT FALSE,
50+
created_timestamp timestamptz NOT NULL DEFAULT NOW()
51+
)
52+
```

src/languages/postgresql/postgresql.keywords.ts

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,7 @@ export const keywords = flatKeywordList({
3535
'BEFORE',
3636
'BEGIN',
3737
'BETWEEN', // (cannot be function or type)
38-
'BIGINT', // (cannot be function or type)
3938
'BINARY', // reserved (can be function or type)
40-
'BIT', // (cannot be function or type)
41-
'BOOLEAN', // (cannot be function or type)
4239
'BOTH', // reserved
4340
'BREADTH',
4441
'BY',
@@ -51,8 +48,6 @@ export const keywords = flatKeywordList({
5148
'CAST', // reserved
5249
'CATALOG',
5350
'CHAIN',
54-
'CHAR', // (cannot be function or type), requires AS
55-
'CHARACTER', // (cannot be function or type), requires AS
5651
'CHARACTERISTICS',
5752
'CHECK', // reserved
5853
'CHECKPOINT',
@@ -99,7 +94,6 @@ export const keywords = flatKeywordList({
9994
'DAY', // requires AS
10095
'DEALLOCATE',
10196
'DEC', // (cannot be function or type)
102-
'DECIMAL', // (cannot be function or type)
10397
'DECLARE',
10498
'DEFAULT', // reserved
10599
'DEFAULTS',
@@ -120,7 +114,6 @@ export const keywords = flatKeywordList({
120114
'DO', // reserved
121115
'DOCUMENT',
122116
'DOMAIN',
123-
'DOUBLE',
124117
'DROP',
125118
'EACH',
126119
'ELSE', // reserved
@@ -148,7 +141,6 @@ export const keywords = flatKeywordList({
148141
'FILTER', // requires AS
149142
'FINALIZE',
150143
'FIRST',
151-
'FLOAT', // (cannot be function or type)
152144
'FOLLOWING',
153145
'FOR', // reserved, requires AS
154146
'FORCE',
@@ -195,10 +187,7 @@ export const keywords = flatKeywordList({
195187
'INSENSITIVE',
196188
'INSERT',
197189
'INSTEAD',
198-
'INT', // (cannot be function or type)
199-
'INTEGER', // (cannot be function or type)
200190
'INTERSECT', // reserved, requires AS
201-
'INTERVAL', // (cannot be function or type)
202191
'INTO', // reserved, requires AS
203192
'INVOKER',
204193
'IS', // reserved (can be function or type)
@@ -260,7 +249,6 @@ export const keywords = flatKeywordList({
260249
'NULL', // reserved
261250
'NULLIF', // (cannot be function or type)
262251
'NULLS',
263-
'NUMERIC', // (cannot be function or type)
264252
'OBJECT',
265253
'OF',
266254
'OFF',
@@ -295,7 +283,6 @@ export const keywords = flatKeywordList({
295283
'POLICY',
296284
'POSITION', // (cannot be function or type)
297285
'PRECEDING',
298-
'PRECISION', // (cannot be function or type), requires AS
299286
'PREPARE',
300287
'PREPARED',
301288
'PRESERVE',
@@ -310,7 +297,6 @@ export const keywords = flatKeywordList({
310297
'QUOTE',
311298
'RANGE',
312299
'READ',
313-
'REAL', // (cannot be function or type)
314300
'REASSIGN',
315301
'RECHECK',
316302
'RECURSIVE',
@@ -363,7 +349,6 @@ export const keywords = flatKeywordList({
363349
'SIMILAR', // reserved (can be function or type)
364350
'SIMPLE',
365351
'SKIP',
366-
'SMALLINT', // (cannot be function or type)
367352
'SNAPSHOT',
368353
'SOME', // reserved
369354
'SQL',
@@ -391,11 +376,8 @@ export const keywords = flatKeywordList({
391376
'TEMP',
392377
'TEMPLATE',
393378
'TEMPORARY',
394-
'TEXT',
395379
'THEN', // reserved
396380
'TIES',
397-
'TIME', // (cannot be function or type)
398-
'TIMESTAMP', // (cannot be function or type)
399381
'TO', // reserved, requires AS
400382
'TRAILING', // reserved
401383
'TRANSACTION',
@@ -427,9 +409,7 @@ export const keywords = flatKeywordList({
427409
'VALIDATOR',
428410
'VALUE',
429411
'VALUES', // (cannot be function or type)
430-
'VARCHAR', // (cannot be function or type)
431412
'VARIADIC', // reserved
432-
'VARYING', // requires AS
433413
'VERBOSE', // reserved (can be function or type)
434414
'VERSION',
435415
'VIEW',
@@ -445,7 +425,6 @@ export const keywords = flatKeywordList({
445425
'WORK',
446426
'WRAPPER',
447427
'WRITE',
448-
'XML',
449428
'XMLATTRIBUTES', // (cannot be function or type)
450429
'XMLCONCAT', // (cannot be function or type)
451430
'XMLELEMENT', // (cannot be function or type)
@@ -459,6 +438,32 @@ export const keywords = flatKeywordList({
459438
'XMLTABLE', // (cannot be function or type)
460439
'YEAR', // requires AS
461440
'YES',
441+
],
442+
// https://www.postgresql.org/docs/current/datatype.html
443+
datatypes: [
444+
'BIGINT', // (cannot be function or type)
445+
'BIT', // (cannot be function or type)
446+
'BOOL', // (cannot be function or type)
447+
'BOOLEAN', // (cannot be function or type)
448+
'CHAR', // (cannot be function or type), requires AS
449+
'CHARACTER', // (cannot be function or type), requires AS
450+
'DECIMAL', // (cannot be function or type)
451+
'DOUBLE',
452+
'FLOAT', // (cannot be function or type)
453+
'INT', // (cannot be function or type)
454+
'INTEGER', // (cannot be function or type)
455+
'INTERVAL', // (cannot be function or type)
456+
'NUMERIC', // (cannot be function or type)
457+
'PRECISION', // (cannot be function or type), requires AS
458+
'REAL', // (cannot be function or type)
459+
'SMALLINT', // (cannot be function or type)
460+
'TEXT',
461+
'TIME', // (cannot be function or type)
462+
'TIMESTAMP', // (cannot be function or type)
463+
'TIMESTAMPTZ', // (cannot be function or type)
464+
'VARCHAR', // (cannot be function or type)
465+
'VARYING', // requires AS
466+
'XML',
462467
'ZONE',
463468
],
464469
});

0 commit comments

Comments
 (0)