Skip to content

fix(pretty_print): indent broken ALTER DOMAIN and drop double space before JSON RETURNING - #882

Merged
psteinroe merged 3 commits into
mainfrom
fix/format-alter-domain-json-value
Oct 20, 2026
Merged

psteinroe merged 3 commits into
mainfrom
fix/format-alter-domain-json-value

Conversation

@psteinroe

Copy link
Copy Markdown
Collaborator

Fixes two small formatter bugs found while working on #871.

ALTER DOMAIN operations are indented when the statement breaks

emit_alter_domain_stmt broke the line before the operation without an indent, so a long ALTER DOMAIN put add constraint (and drop constraint, validate constraint, set/drop default, set/drop not null) at column 0. The operation now sits in an indent, the same way ALTER TABLE indents its commands:

-- before
alter domain public.email_address
add constraint email_address_not_blank check (
  value <> '' and value is not null and length(value) > 3
) not valid;

-- after
alter domain public.email_address
  add constraint email_address_not_blank check (
    value <> '' and value is not null and length(value) > 3
  ) not valid;

Short statements still fit on one line (alter domain public.short_domain drop not null;).

No double space before RETURNING in JSON functions

json_value, json_query, json_arrayagg and json_objectagg emit a soft line before RETURNING, then called emit_json_output with has_content = true, which adds its own space. When the group stayed flat, that printed two spaces:

-- before
select json_value(cast('123' as jsonb), '$'  returning int);
select json_arrayagg(i absent on null  returning jsonb) from t;
-- after
select json_value(cast('123' as jsonb), '$' returning int);
select json_arrayagg(i absent on null returning jsonb) from t;

These four call sites no longer ask for the extra space. json_object, json_array, json_serialize, json_parse, the JsonAggConstructor tail and json_table don't emit a line before RETURNING, so they already used a single space and stay unchanged. json_exists takes no RETURNING clause.

Tests and snapshot changes

  • New fixtures: multi/alter_domain_layout.sql (every ALTER DOMAIN subtype, broken and flat) and multi/json_returning.sql (flat and broken RETURNING across the JSON functions). They were committed first with the output from main, so the fix commits show the before/after.
  • check_constraint_body* snapshots: only the ALTER DOMAIN statement changes (it is now indented).
  • sqljson* and sqljson_queryfuncs* snapshots: changes are whitespace only (I checked this by collapsing whitespace on both sides). A few statements now fit within the line width and collapse onto one line.

Risks

Output changes only. No snapshot has a mid-line double space before a JSON clause keyword any more. Out of scope: when a json_value/json_query call breaks, its clauses are still not indented relative to the opening parenthesis (see the long cases in json_returning).

@psteinroe
psteinroe merged commit 654ce5c into main Oct 20, 2026
11 checks passed
@psteinroe
psteinroe deleted the fix/format-alter-domain-json-value branch October 20, 2026 10:17
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