| privatestaticreadonlyRESERVED_WORDS=newSet([ |
| 'all','analyse','analyze','and','any','array','as','asc','asymmetric','both', |
| 'case','cast','check','collate','column','constraint','create','current_catalog', |
| 'current_date','current_role','current_time','current_timestamp','current_user', |
| 'default','deferrable','desc','distinct','do','else','end','except','false', |
| 'fetch','for','foreign','from','grant','group','having','in','initially', |
| 'intersect','into','lateral','leading','limit','localtime','localtimestamp', |
| 'not','null','offset','on','only','or','order','placing','primary', |
| 'references','returning','select','session_user','some','symmetric','table', |
| 'then','to','trailing','true','union','unique','user','using','variadic', |
| 'when','where','window','with' |
| ]); |
| |
| privatestaticneedsQuotes(value: string): boolean{ |
| if(!value)returnfalse; |
| |
| constneedsQuotesRegex=/[a-z]+[\W\w]*[A-Z]+|[A-Z]+[\W\w]*[a-z]+|\W/; |
| |
| constisAllUppercase=/^[A-Z]+$/.test(value); |
| |
| returnneedsQuotesRegex.test(value)|| |
| Deparser.RESERVED_WORDS.has(value.toLowerCase())|| |
| isAllUppercase; |
| } |
Our Code
pgsql-parser/packages/deparser/src/deparser.ts
Lines 2460 to 2483 in bf4612f
PG Source
https://github.com/postgres/postgres/blob/fab5cd3dd1323f9e66efeb676c4bb212ff340204/src/backend/utils/adt/ruleutils.c#L13055-L13137
https://github.com/postgres/postgres/blob/fab5cd3dd1323f9e66efeb676c4bb212ff340204/src/backend/utils/adt/ruleutils.c#L13139-L13156
doxygen
https://doxygen.postgresql.org/ruleutils_8c.html#a8c18b3ffb8863e7740b32ef5f4c05ddc
and keywords too