Skip to content

fix(pretty-print): keep qualified names in ALTER ... SET SCHEMA and RENAME - #827

Merged
psteinroe merged 1 commit into
mainfrom
fix/pretty-print-alter-object-names
Oct 2, 2026
Merged

psteinroe merged 1 commit into
mainfrom
fix/pretty-print-alter-object-names

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Qualified object names in ALTER ... SET SCHEMA and ALTER ... RENAME no longer print with commas, and ALTER TYPE ... RENAME ATTRIBUTE keeps its type name and CASCADE. Before this, the formatted output for these statements did not re-parse.

-- before
alter domain alter1, posint set schema alter2;
alter type rename attribute a to aa;
-- after
alter domain alter1.posint set schema alter2;
alter type test_type2 rename attribute a to aa cascade;

Qualified names

The parser stores any_name objects (types, domains, conversions, text search objects, collations, statistics) as a list of strings. The generic list emitter joined them with commas; they are now dot-separated, the same way alter_owner_stmt already handles them. In RenameStmt this also fixes qualified names in RENAME TO and domain RENAME CONSTRAINT. Neither appears in the Postgres regression corpus, but both have the same cause.

RENAME ATTRIBUTE

The composite type name lives in relation, not object, so it was dropped. It is now emitted without ONLY (the RangeVar has inh = false), and CASCADE is kept.

Fixes the ALTER object-name group of the round-trip failures found in #824. The new fixtures only add snapshots; no existing snapshot changes.

@psteinroe psteinroe added the ready label Oct 2, 2026
@psteinroe
psteinroe merged commit 0be7348 into main Oct 2, 2026
9 checks passed
@psteinroe
psteinroe deleted the fix/pretty-print-alter-object-names branch October 2, 2026 10:10
psteinroe added a commit that referenced this pull request Oct 2, 2026
)

Commit Postgres' own regression SQL (`src/test/regress/sql`) for every
supported major version, together with the verdict Postgres gave each
statement, so tests can run against real-world SQL without the network
or a database.

**Fixtures**

`crates/pgls_postgres_regress/data/<major>/` holds the pinned tag
(`REL_15_19`, `REL_16_15`, `REL_17_11`, `REL_18_6`), the upstream files
verbatim, and one `line:col verdict` file per SQL file, where the
verdict is `accepted`, `rejected <sqlstate>` or `skipped`.
`collate.windows.win1252.sql` is left out because it is not UTF-8 and
only runs on Windows. The data is marked `linguist-generated`, so the
diff collapses.

**Loader and recorder**

The crate's loader preprocesses each file (blanking psql meta-commands
and `COPY` data, so line numbers are kept), splits it with
`pgls_statement_splitter` and attaches the recorded verdicts. It panics
with "fixtures out of date, run `just record-regress <major>`" when the
split no longer matches. `just record-regress <major> [tag]` fetches the
tag, starts the matching `postgres` image in Docker, checks the server
version and runs every statement in a fresh database per file. The
semantics are the same as the existing type-check regression harness: 5s
statement timeout, transaction control and client `COPY` skipped,
`raw_sql`, roles cleaned up after each file.

**First consumer: pretty-print round trip**

A new `pgls_pretty_print` test formats every statement Postgres 15–17
accepted (about 92k), at widths 80 and 100, and requires the output to
parse back to the same normalized AST. Versions newer than the parser
are skipped. The formatter bugs it found are fixed in #825, #826, #827,
#828, #829 and #830, so it passes without an allowlist.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant