MemberJunction / MemberJunction/MJ
PostgreSQL auto-quote: the deliberate-exclusion guard covers 7 of the 17 excluded words
- Dominant language
- TSQL
- Stars
- 29
- Forks
- 6
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 323
Description
## What
`packages/SQLDialect/src/postgresqlAutoQuote.ts` deliberately **excludes** seventeen non-reserved PostgreSQL words from `PostgreSQLQuotingKeywords`, on the reasoning that each is a legal bare column name and a believable ALL-CAPS identifier in a customer schema:
```
LEVEL, MODE, OPTION, SHARE, START, CACHE, ROLE, PASSWORD, LOGIN,
DOMAIN, CLUSTER, POLICY, SEQUENCE, LOCAL, SKIP, EXCLUSIVE, SOURCE
```
A test pins the exclusion so it stays deliberate rather than becoming incidental — `postgresqlAutoQuote.test.ts:225`:
```ts
for (const word of ['USER', 'LEVEL', 'MODE', 'OPTION', 'SHARE', 'START', 'CACHE', 'POLICY']) {
// ... must stay quoted
}
```
That is `USER` plus **7 of the 17**. The remaining ten — `ROLE`, `PASSWORD`, `LOGIN`, `DOMAIN`, `CLUSTER`, `SEQUENCE`, `LOCAL`, `SKIP`, `EXCLUSIVE`, `SOURCE` — appear **zero times** in either `postgresqlAutoQuote.test.ts` or `postgresqlAutoQuote.baseline.test.ts`.
## Why it is worth closing
**Nothing is broken today.** None of the seventeen is in the keyword set, so all seventeen are quoted correctly with or without a test. This is purely about the guard, not about behavior.
The guard exists to stop a *future* change from sweeping one of these words into the keyword set. That is not hypothetical in the abstract: #4436 added roughly eighty words in a single pass, and a later pass of the same kind is exactly how one of the ten would slip in. If `SEQUENCE` were added, an ALL-CAPS `SEQUENCE` column in a customer schema would stop being quoted and would resolve as the keyword instead.
There is also a small irony worth recording: #4436's own thesis is that *"sampling is precisely what let `CURRENT_DATE` through"* — and this guard is sampled.
## Fix
Extend the array at `postgresqlAutoQuote.test.ts:225` to all seventeen words (plus `USER`). It is a one-line change to a literal; the assertion body already does the right thing.
Worth pulling the list from a single exported constant shared with the source comment, so the two cannot drift again.
Found during review of #4436 and deliberately **not** requested as a change on that PR — the PR is correct as written and this is a test-completeness follow-up.
Contributor guide
Research direction
Start in packages/SQLDialect/src/postgresqlAutoQuote.test.ts at line 225 and compare the guard with the exclusion list in postgresqlAutoQuote.ts. Extend the test literal to include all seventeen excluded words plus USER, then run postgresqlAutoQuote.test.ts and postgresqlAutoQuote.baseline.test.ts. Done means every deliberate exclusion is covered by the guard.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgresql, typescript
- Domain
- databases, testing
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 90/100