Skip to content

Fix PG 18 FETCH WITH TIES, COPY FORMAT, and tablespace deparsing - #403

Merged
pyramation merged 1 commit into
mainfrom
feat/deparse-fetch-ties-copy-tablespaces
Nov 23, 2026
Merged

pyramation merged 1 commit into
mainfrom
feat/deparse-fetch-ties-copy-tablespaces

Conversation

@pyramation

@pyramation pyramation commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Preserve WITH TIES (including an omitted count), case-sensitive COPY FORMAT values, and tablespace and index constraint clauses on a PG 18 parse → deparse → parse round trip. Use grammar order for CREATE TABLE ... USING ... WITH ... ON COMMIT ... TABLESPACE and preserve the distinction between string and typed storage option values.

Adds generated kitchen-sink coverage for the fixes and removes 40 newly passing statements from the PostgreSQL regression ratchet.

Reimplements the remaining deparser fixes from #368 on current main.


libpg-query and parser opened this PR for Dan
Implemented in session Redo WITH TIES and COPY FORMAT deparsing
Review with Devin · Open in Devin Desktop


Summary by CodeRabbit

  • Bug Fixes
    • Improved SQL formatting for FETCH ... WITH TIES, including row counts, offsets, and expressions.
    • Corrected output for PostgreSQL COPY format options and tablespace statements.
    • Improved formatting of table and index clauses, including constraints, included columns, and storage options.
  • Tests
    • Expanded coverage for these SQL features and updated regression expectations.

@luxor-code-review

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

Copy link
Copy Markdown

Review complete. No issues found — approved ✅.


This PR extends the deparser with several clause families that previously failed round-trip, and locks them in with new fixtures that clear 30 known-failure regressions.

Files Change
packages/deparser/src/deparser.ts Emits FETCH FIRST n ROWS WITH TIES from limitOption, reorders CreateStmt USING/WITH/TABLESPACE emission with quoted identifiers, adds appendIndexConstraintOptions and deparseRelOptions helpers, and switches COPY format values between bare words and quoted literals.
packages/pgsql-types/src/{types.ts,field-metadata.json} Widens SelectStmt_limitCount to include ParamRef, matching parameterized FETCH counts.
__fixtures__/*, packages/deparser/__tests__/* New fetch-with-ties, tablespace-clauses, and extended pg18-copy kitchen-sink fixtures/tests; removes now-passing entries from known-failures.deparser.json.

No high-confidence defects were found; three low-severity observations (duplicated rel-options rendering in CreateStmt, degenerate empty-string COPY format, non-scalar DefElem args in deparseRelOptions) were noted but fell below the reporting threshold.

Reviewed commit: 244261f

@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 23, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The deparser now formats FETCH WITH TIES, table and index constraint options, tablespace statements, and COPY format values. Fixtures and tests cover these SQL forms. Regression fixture mappings were updated.

Changes: SQL deparser syntax coverage

Layer / File(s) Summary
FETCH WITH TIES output
packages/deparser/src/deparser.ts, __fixtures__/kitchen-sink/misc/fetch-with-ties.sql, packages/deparser/__tests__/kitchen-sink/misc-fetch-with-ties.test.ts
SelectStmt emits FETCH FIRST ... ROWS WITH TIES and handles optional counts and expressions. Seven fixture cases are added and tested.
Table and index constraint clauses
packages/deparser/src/deparser.ts, __fixtures__/kitchen-sink/misc/tablespace-clauses.sql, __fixtures__/regress/known-failures.deparser.json
CreateStmt adjusts the order and quoting of access methods, options, and tablespace names. Primary-key, unique, and exclusion constraints use shared index-option formatting. Fixtures cover table and index clauses. Regression mappings for index-including and limit cases are removed.
Tablespace names and options
packages/deparser/src/deparser.ts, __fixtures__/kitchen-sink/misc/tablespace-clauses.sql, packages/deparser/__tests__/kitchen-sink/misc-tablespace-clauses.test.ts, __fixtures__/regress/known-failures.deparser.json
Tablespace statements quote names and use shared relation-option formatting. Fixtures cover creation, alteration, and deletion. Regression mappings are updated.
COPY format values
packages/deparser/src/deparser.ts, __fixtures__/kitchen-sink/misc/pg18-copy.sql, packages/deparser/__tests__/kitchen-sink/misc-pg18-copy.test.ts
COPY format strings remain bare only when identifier quoting leaves them unchanged; other values use E-strings. Additional COPY fixture cases are included in the test list.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Suggested reviewers: luxor-code-review

Merge Risk: Minimal · up to 24426 · assessed changes only

Path filters excluded changed files. This rating applies only to the assessed changes.

Security architecture risk: Minimal · up to 24426

The change affects the SQL text callers receive, not who can execute it or what permissions they have. The reviewed changes did not establish a new security or rollback risk.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — The direct effect is on SQL text received by library consumers. Database or filesystem effects from rendered COPY or tablespace statements would require a downstream executor acting with its own authority; neither the inspected public entrypoint nor the revert helper executes the text.

Trust Boundaries and Controls

  • observed — The new quoting calls govern how input values are represented in SQL. They do not authorize COPY, tablespace operations, or access to the resources those statements name.
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 three fixes: PG 18 FETCH ... WITH TIES, COPY FORMAT handling, and tablespace deparsing. The raw summary and objectives confirm all three. The deparser changes cover SelectStmt WITH TIE…
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 three fixes: PG 18 FETCH ... WITH TIES, COPY FORMAT handling, and tablespace deparsing. The raw summary and objectives confirm all three. The deparser changes cover SelectStmt WITH TIES output, DefElem COPY format quoting, and tablespace name quoting plus shared option formatting. The title is specific and matches the main changes, though it does not mention the CREATE TABLE clause ordering and constraint index changes.

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 879314a and 244261f.

Files ignored due to path filters: 3

  • __fixtures__/generated/generated.json is excluded by !**/generated/**, !__fixtures__/generated/**
  • packages/pgsql-types/src/field-metadata.json is excluded by !packages/pgsql-types/src/field-metadata.json
  • packages/pgsql-types/src/types.ts is excluded by !packages/pgsql-types/src/types.ts
Files selected for processing: 8

  • __fixtures__/kitchen-sink/misc/fetch-with-ties.sql
  • __fixtures__/kitchen-sink/misc/pg18-copy.sql
  • __fixtures__/kitchen-sink/misc/tablespace-clauses.sql
  • __fixtures__/regress/known-failures.deparser.json
  • packages/deparser/__tests__/kitchen-sink/misc-fetch-with-ties.test.ts
  • packages/deparser/__tests__/kitchen-sink/misc-pg18-copy.test.ts
  • packages/deparser/__tests__/kitchen-sink/misc-tablespace-clauses.test.ts
  • packages/deparser/src/deparser.ts
Files with no reviewable changes: 1

  • fixtures/regress/known-failures.deparser.json

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

@pyramation
pyramation merged commit e7a3230 into main Nov 23, 2026
23 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