Skip to content

Conversation

@pyramation
Copy link
Collaborator

No description provided.

- Remove hardcoded RESERVED_WORDS from quote-utils.ts
- Import RESERVED_KEYWORDS and TYPE_FUNC_NAME_KEYWORDS from kwlist.ts
- Add explicit Set<string> type annotations to kwlist.ts exports for proper TypeScript compatibility
- QuoteUtils.needsQuotes() now uses the centralized keyword sets

Co-Authored-By: Dan Lynch <[email protected]>
…ions

The generated kwlist.ts needs explicit Set<string> type annotations for
TypeScript compatibility when calling .has() with string arguments.

Co-Authored-By: Dan Lynch <[email protected]>
…Utils

- Remove Deparser.RESERVED_WORDS and Deparser.needsQuotes from deparser.ts
- Add QuoteUtils.needsQuotesForString() and QuoteUtils.quoteString() methods
- Update all call sites to use QuoteUtils instead of Deparser methods
- Both QuoteUtils.needsQuotes and QuoteUtils.needsQuotesForString now use
  RESERVED_KEYWORDS from kwlist.ts as the single source of truth
- Add Set<string> type annotations to kwlist.ts exports for TypeScript compatibility

Co-Authored-By: Dan Lynch <[email protected]>
…L ruleutils.c

Port PostgreSQL's quote_identifier() and quote_qualified_identifier() functions
to TypeScript. These functions properly:
- Quote identifiers only when needed (lowercase letters, digits, underscores)
- Escape embedded double quotes as ""
- Check against keyword categories (quote all except UNRESERVED_KEYWORD)

References:
- 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

Co-Authored-By: Dan Lynch <[email protected]>
…precated methods

- Replace all quoteString usages in deparser.ts with quoteIdentifier
- Replace all needsQuotesForString usages with quoteIdentifier checks
- Remove deprecated quoteString and needsQuotesForString methods from quote-utils.ts
- Update quoteIfNeeded() and String() methods to use quoteIdentifier
- Migrate DefElem contexts and VariableSetStmt to use quoteIdentifier

The quoteIdentifier function is more correct because it:
- Properly escapes embedded double quotes as ""
- Checks all keyword categories (not just RESERVED_KEYWORDS)
- Follows PostgreSQL's exact quote_identifier() logic from ruleutils.c

Co-Authored-By: Dan Lynch <[email protected]>
…precated methods

- Replace all QuoteUtils.quote() usages with QuoteUtils.quoteIdentifier()
- Remove deprecated needsQuotes() and quote() methods from quote-utils.ts
- QuoteUtils now only exports: escape, escapeEString, formatEString, needsEscapePrefix, quoteIdentifier, quoteQualifiedIdentifier

This completes the migration to PostgreSQL-accurate identifier quoting.

Co-Authored-By: Dan Lynch <[email protected]>
Type names like 'int' and 'timestamp' should not be quoted even though
they are TYPE_FUNC_NAME_KEYWORDS. The quoteIdentifier function is meant
for SQL identifiers (table names, column names, etc.), not for type names
which have their own grammar rules in PostgreSQL.

Co-Authored-By: Dan Lynch <[email protected]>
Replaced 11 instances of manual schema.name concatenation with
quoteQualifiedIdentifier() for cleaner, more maintainable code:
- RangeVar: schema.table patterns
- DropStmt: operator class/family with schema
- AlterObjectSchemaStmt: domain, type, conversion, parser, config,
  template, dictionary, operator class/family patterns

Co-Authored-By: Dan Lynch <[email protected]>
@pyramation pyramation merged commit 4346617 into main Dec 22, 2025
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants