Skip to content

fix(plpgsql-deparser): keep quotes on the internal "char" type - #388

Merged
pyramation merged 2 commits into
mainfrom
fix/plpgsql-deparser-quoted-char
Nov 21, 2026
Merged

pyramation merged 2 commits into
mainfrom
fix/plpgsql-deparser-quoted-char

Conversation

@pyramation

@pyramation pyramation commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Unqualified datatype names had all their quotes stripped. That breaks "char": it is a distinct single-byte internal type, and unquoted char means character(1).

DECLARE c "char" := 'a';   ->   DECLARE c char := 'a';   (different type)

"char" and "char"[] now keep their quotes; every other type is unchanged. A fixture and test are added.

This is a fresh version of the "char" part of #365 (its other two fixes are already on main). It's part of constructive-io/constructive-planning#2555.


libpg-query and parser opened this PR for Dan
Implemented in session Triage stale open PRs and issues in parser repos
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • Bug Fixes
    • Preserved quotation marks for PostgreSQL’s internal "char" type in declarations, including array types, while leaving ordinary char unchanged.
    • Preserved required quoting in simple type declarations for reserved words, mixed-case names, spaces, embedded quotes, dotted names, and array types.

@luxor-code-review

luxor-code-review Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 1 medium

💬 Inline comments (1)

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Add negative assertion for ordinary char control case (quoted-char.test.ts:15) — The fixture deliberately contrasts c "char" with ordinary char (fixture comment: 'internal "char" declarations retain their distinct type'), but the new test at packages/plpgsql-deparser/__tests__/quoted-char.test.ts lines 15-16 only makes positive toContain checks.

The change makes the deparser emit the quoted internal "char" type verbatim (including array suffixes) instead of stripping its quotes, while leaving ordinary char and other simple type names unchanged.

Files Change
packages/plpgsql-deparser/src/plpgsql-deparser.ts Adds a "char" (with optional array suffix) special case to the type-name quote-stripping logic in deparseType.
packages/plpgsql-deparser/__tests__/quoted-char.test.ts + snapshot Adds a regression test with snapshot covering internal "char" declarations.
__fixtures__/plpgsql/plpgsql_deparser_fixes.sql + __fixtures__/plpgsql-generated/generated.json Adds fixture declarations contrasting internal "char" with ordinary char and regenerates the fixture index.

Reviewed commit: 543cbd4

@devin-ai-integration

Copy link
Copy Markdown
Contributor

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The PL/pgSQL deparser now preserves required quoting in simple type names, including "char" and array types. Fixtures and tests cover these cases and type names containing reserved words, spaces, mixed case, embedded quotes, or dots.

Changes: Quoted PL/pgSQL type deparsing

Layer / File(s) Summary
Quoted type deparsing and coverage
packages/plpgsql-deparser/src/plpgsql-deparser.ts, __fixtures__/plpgsql/plpgsql_deparser_fixes.sql, packages/plpgsql-deparser/__tests__/quoted-char.test.ts
deparseType handles fully quoted simple identifiers and optional array suffixes. It decodes doubled quotes and re-quotes identifiers, with special handling for "char". Fixtures and tests cover internal and ordinary char, other quoted identifiers, array types, and an unquoted simple type.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: Minimal · up to 0f3ca

This change keeps required quotes on PL/pgSQL type names, so the internal "char" type is no longer turned into char (character(1)). Fixtures and tests cover the new behavior. No merge-blocking risk was identified.

Security architecture risk: Minimal · up to 0f3ca

The change preserves required quoting in generated PL/pgSQL type declarations without adding execution capabilities or changing access controls. No introduced or worsened architecture-level security risk was established.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the primary change: the deparser now keeps quotes on the internal "char" type. The raw summary confirms that deparseType keeps quotes for char, and the fixture and test cover "char" an…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the primary change: the deparser now keeps quotes on the internal "char" type. The raw summary confirms that deparseType keeps quotes for char, and the fixture and test cover "char" and "char"[]. The title also uses the conventional fix(scope) format. It does not cover the broader quoting of other simple type names, which is acceptable because the title focuses on the main point.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 543cbd4 and 0f3ca11.

Files ignored due to path filters: 2

  • __fixtures__/plpgsql-generated/generated.json is excluded by !__fixtures__/plpgsql-generated/**
  • packages/plpgsql-deparser/__tests__/__snapshots__/quoted-char.test.ts.snap is excluded by !**/*.snap, !**/__snapshots__/**
Files selected for processing: 3

  • __fixtures__/plpgsql/plpgsql_deparser_fixes.sql
  • packages/plpgsql-deparser/__tests__/quoted-char.test.ts
  • packages/plpgsql-deparser/src/plpgsql-deparser.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR fixes the PL/pgSQL deparser to preserve the quoted internal "char" type name in variable declarations, with fixtures and snapshot tests.

Key findings

// Simple type - just strip quotes and return as-is
return typname.replace(/"/g, '').trim();
const trimmed = typname.trim();
return /^"char"(\[\d*\])*$/.test(trimmed) ? trimmed : trimmed.replace(/"/g, '');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 bug · medium

Guard strips quotes from every other quoted type name

The new branch preserves quotes only for the exact "char" pattern; every other quoted simple type name still hits trimmed.replace(/"/g, '') at packages/plpgsql-deparser/src/plpgsql-deparser.ts line 887. A declaration such as v "end" or a type name containing spaces arrives quoted from the parser (the fixture proves quoted typnames pass through verbatim) and is deparsed as the bare keyword or unquoted token, which fails to re-parse or changes meaning. Only "char" was fixed; the wholesale strip remains for all other quoted names.

📋 Prompt for AI Agents

In packages/plpgsql-deparser/src/plpgsql-deparser.ts line 887 (the !isSchemaQualified branch of deparseType), replace the unconditional trimmed.replace(/"/g, '') with logic that strips surrounding quotes only when the unquoted name is a valid identifier that would not need re-quoting (e.g. compare QuoteUtils.quoteIdentifier(unquoted) against the unquoted form). Keep the existing /^"char"([\d*])*$/ special case. This prevents keyword-named or space-containing quoted type names from being emitted unquoted and breaking round-trip parsing.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Devin Review

@pyramation
pyramation merged commit 4715d6d into main Nov 21, 2026
22 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.

1 participant